Skip to content

Commit 2cc0088

Browse files
committed
Switch to integer division inaddPaddingUpTo. Rename magic constants in LoggingASTScopeDeclConsumer. Format BridgedConsumedLookupResult.
1 parent 1d94844 commit 2cc0088

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,15 @@ struct BridgedConsumedLookupResult {
9191

9292
SWIFT_NAME("nameLoc")
9393
BridgedSourceLoc NameLoc;
94-
94+
9595
SWIFT_NAME("flag")
9696
SwiftInt Flag;
97-
97+
9898
#ifdef USED_IN_CPP_SOURCE
9999
BridgedConsumedLookupResult(swift::Identifier name,
100-
swift::SourceLoc sourceLoc,
101-
SwiftInt flag
102-
) : Name(BridgedIdentifier(name)),
103-
NameLoc(BridgedSourceLoc(sourceLoc)),
104-
Flag(flag) {}
100+
swift::SourceLoc sourceLoc, SwiftInt flag)
101+
: Name(BridgedIdentifier(name)), NameLoc(BridgedSourceLoc(sourceLoc)),
102+
Flag(flag) {}
105103
#endif
106104
};
107105

lib/AST/ASTScope.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ using namespace ast_scope;
4343
class LoggingASTScopeDeclConsumer
4444
: public namelookup::AbstractASTScopeDeclConsumer {
4545
private:
46+
const int shouldLookInMembers = 0b10;
4647
namelookup::AbstractASTScopeDeclConsumer *originalConsumer;
4748

4849
public:
@@ -69,21 +70,21 @@ class LoggingASTScopeDeclConsumer
6970
/// \return true if the lookup should be stopped at this point.
7071
bool consume(ArrayRef<ValueDecl *> values,
7172
NullablePtr<DeclContext> baseDC = nullptr) override {
72-
bool result = originalConsumer->consume(values, baseDC);
73+
bool endOfLookup = originalConsumer->consume(values, baseDC);
7374

7475
for (auto value : values) {
7576
if (auto sourceLoc = value->getLoc()) {
7677
recordedElements.push_back(BridgedConsumedLookupResult(
77-
value->getBaseIdentifier(), sourceLoc, result));
78+
value->getBaseIdentifier(), sourceLoc, endOfLookup));
7879
} else {
7980
// If sourceLoc is unavailable, use location of it's parent.
8081
recordedElements.push_back(BridgedConsumedLookupResult(
8182
value->getBaseIdentifier(),
82-
value->getDeclContext()->getAsDecl()->getLoc(), result));
83+
value->getDeclContext()->getAsDecl()->getLoc(), endOfLookup));
8384
}
8485
}
8586

86-
return result;
87+
return endOfLookup;
8788
};
8889

8990
/// Look for members of a nominal type or extension scope.
@@ -93,19 +94,19 @@ class LoggingASTScopeDeclConsumer
9394
///
9495
/// \return true if the lookup should be stopped at this point.
9596
bool lookInMembers(const DeclContext *scopeDC) const override {
96-
bool result = originalConsumer->lookInMembers(scopeDC);
97+
bool endOfLookup = originalConsumer->lookInMembers(scopeDC);
9798

9899
if (auto *extDecl = dyn_cast<ExtensionDecl>(scopeDC)) {
99100
recordedElements.push_back(BridgedConsumedLookupResult(
100101
Identifier(), extDecl->getExtendedTypeRepr()->getLoc(),
101-
0b10 + result));
102+
shouldLookInMembers + endOfLookup));
102103
} else {
103104
recordedElements.push_back(BridgedConsumedLookupResult(
104105
scopeDC->getSelfNominalTypeDecl()->getBaseIdentifier(),
105-
scopeDC->getAsDecl()->getLoc(), 0b10 + result));
106+
scopeDC->getAsDecl()->getLoc(), shouldLookInMembers + endOfLookup));
106107
}
107108

108-
return result;
109+
return endOfLookup;
109110
};
110111

111112
/// Called for local VarDecls that might not yet be in scope.

lib/ASTGen/Sources/ASTGen/LexicalLookup.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,11 @@ extension String {
598598
var leftPad = ""
599599
var rightPad = ""
600600

601-
for _ in 0..<Int(floor(Double(lengthDifference) / 2.0)) {
601+
for _ in 0..<(lengthDifference / 2) {
602602
leftPad += " "
603603
}
604604

605-
for _ in 0..<Int(ceil(Double(lengthDifference) / 2.0)) {
605+
for _ in 0..<((lengthDifference + 1) / 2) {
606606
rightPad += " "
607607
}
608608

0 commit comments

Comments
 (0)