Skip to content

Commit 9126414

Browse files
committed
[NFC] Stub module selector DeclNameRef/Loc members
1 parent b978501 commit 9126414

File tree

6 files changed

+101
-33
lines changed

6 files changed

+101
-33
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,23 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
215215
BridgedSourceLoc cLParenLoc, BridgedArrayRef cLabelLocs,
216216
BridgedSourceLoc cRParenLoc);
217217

218+
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:moduleSelectorLoc:baseNameLoc:"
219+
"lParenLoc:argumentLabelLocs:rParenLoc:)")
220+
BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
221+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
222+
BridgedSourceLoc cBaseNameLoc, BridgedSourceLoc cLParenLoc,
223+
BridgedArrayRef cLabelLocs, BridgedSourceLoc cRParenLoc);
224+
218225
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:)")
219226
BridgedDeclNameLoc
220227
BridgedDeclNameLoc_createParsed(BridgedSourceLoc cBaseNameLoc);
221228

229+
SWIFT_NAME("BridgedDeclNameLoc.createParsed(_:moduleSelectorLoc:baseNameLoc:)")
230+
BridgedDeclNameLoc
231+
BridgedDeclNameLoc_createParsed(
232+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
233+
BridgedSourceLoc cBaseNameLoc);
234+
222235
//===----------------------------------------------------------------------===//
223236
// MARK: ASTContext
224237
//===----------------------------------------------------------------------===//

include/swift/AST/DeclNameLoc.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "swift/Basic/LLVM.h"
2121
#include "swift/Basic/SourceLoc.h"
2222

23+
#include "llvm/ADT/ArrayRef.h"
24+
2325
class BridgedDeclNameLoc;
2426

2527
namespace swift {
@@ -71,13 +73,24 @@ class DeclNameLoc {
7173
explicit DeclNameLoc(SourceLoc baseNameLoc)
7274
: DeclNameLoc(baseNameLoc.getOpaquePointerValue(), 0) {}
7375

76+
explicit DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
77+
SourceLoc baseNameLoc)
78+
: DeclNameLoc(baseNameLoc) { }
79+
7480
/// Create declaration name location information for a compound
7581
/// name.
7682
DeclNameLoc(ASTContext &ctx, SourceLoc baseNameLoc,
7783
SourceLoc lParenLoc,
7884
ArrayRef<SourceLoc> argumentLabelLocs,
7985
SourceLoc rParenLoc);
8086

87+
DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
88+
SourceLoc baseNameLoc,
89+
SourceLoc lParenLoc,
90+
ArrayRef<SourceLoc> argumentLabelLocs,
91+
SourceLoc rParenLoc)
92+
: DeclNameLoc(ctx, baseNameLoc, lParenLoc, argumentLabelLocs, rParenLoc) { }
93+
8194
/// Whether the location information is valid.
8295
bool isValid() const { return getBaseNameLoc().isValid(); }
8396

@@ -111,6 +124,10 @@ class DeclNameLoc {
111124
return getSourceLocs()[FirstArgumentLabelIndex + index];
112125
}
113126

127+
SourceLoc getModuleSelectorLoc() const {
128+
return SourceLoc();
129+
}
130+
114131
SourceLoc getStartLoc() const {
115132
return getBaseNameLoc();
116133
}

include/swift/AST/Identifier.h

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -693,65 +693,73 @@ class DeclNameRef {
693693
void *getOpaqueValue() const { return FullName.getOpaqueValue(); }
694694
static DeclNameRef getFromOpaqueValue(void *p);
695695

696+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
697+
DeclName fullName)
698+
: FullName(fullName) { }
699+
700+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
701+
DeclBaseName baseName, ArrayRef<Identifier> argLabels)
702+
: FullName(C, baseName, argLabels) { }
703+
696704
explicit DeclNameRef(DeclName FullName)
697705
: FullName(FullName) { }
698706

699-
explicit DeclNameRef(DeclBaseName BaseName)
700-
: FullName(BaseName) { }
707+
bool hasModuleSelector() const {
708+
return false;
709+
}
701710

702-
explicit DeclNameRef(Identifier BaseName)
703-
: FullName(BaseName) { }
711+
Identifier getModuleSelector() const {
712+
return Identifier();
713+
}
704714

705715
/// The name of the declaration being referenced.
706716
DeclName getFullName() const {
707717
return FullName;
708718
}
709719

710-
DeclName &getFullName() {
711-
return FullName;
712-
}
713-
714720
/// The base name of the declaration being referenced.
715721
DeclBaseName getBaseName() const {
716-
return FullName.getBaseName();
722+
return getFullName().getBaseName();
717723
}
718724

719725
Identifier getBaseIdentifier() const {
720-
return FullName.getBaseIdentifier();
726+
return getFullName().getBaseIdentifier();
721727
}
722728

723729
ArrayRef<Identifier> getArgumentNames() const {
724-
return FullName.getArgumentNames();
730+
return getFullName().getArgumentNames();
725731
}
726732

727733
bool isSimpleName() const {
728-
return FullName.isSimpleName();
734+
return getFullName().isSimpleName();
729735
}
730736

731737
bool isSimpleName(DeclBaseName name) const {
732-
return FullName.isSimpleName(name);
738+
return getFullName().isSimpleName(name);
733739
}
734740

735741
bool isSimpleName(StringRef name) const {
736-
return FullName.isSimpleName(name);
742+
return getFullName().isSimpleName(name);
737743
}
738744

739745
bool isSpecial() const {
740-
return FullName.isSpecial();
746+
return getFullName().isSpecial();
741747
}
742748

743749
bool isOperator() const {
744-
return FullName.isOperator();
750+
return getFullName().isOperator();
745751
}
746752

747-
bool mustAlwaysBeEscaped() const { return FullName.mustAlwaysBeEscaped(); }
753+
bool mustAlwaysBeEscaped() const {
754+
return getFullName().mustAlwaysBeEscaped();
755+
}
748756

749757
bool isCompoundName() const {
750-
return FullName.isCompoundName();
758+
return getFullName().isCompoundName();
751759
}
752760

753761
explicit operator bool() const {
754-
return (bool)FullName;
762+
return (bool)getFullName();
755763
}
756764

757765
/// Compare two declaration names, producing -1 if \c *this comes before
@@ -825,12 +833,12 @@ inline DeclNameRef DeclNameRef::getFromOpaqueValue(void *p) {
825833
}
826834

827835
inline DeclNameRef DeclNameRef::withoutArgumentLabels(ASTContext &C) const {
828-
return DeclNameRef(getBaseName());
836+
return DeclNameRef(C, getModuleSelector(), getBaseName());
829837
}
830838

831839
inline DeclNameRef DeclNameRef::withArgumentLabels(
832840
ASTContext &C, ArrayRef<Identifier> argumentNames) const {
833-
return DeclNameRef(DeclName(C, getBaseName(), argumentNames));
841+
return DeclNameRef(C, getModuleSelector(), getBaseName(), argumentNames);
834842
}
835843

836844
inline DeclNameRef DeclNameRef::createSubscript() {

lib/AST/Bridging/DeclBridging.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,23 @@ BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
7070
BridgedASTContext cContext, BridgedSourceLoc cBaseNameLoc,
7171
BridgedSourceLoc cLParenLoc, BridgedArrayRef cLabelLocs,
7272
BridgedSourceLoc cRParenLoc) {
73+
return BridgedDeclNameLoc_createParsed(
74+
cContext, BridgedSourceLoc(), cBaseNameLoc, cLParenLoc, cLabelLocs,
75+
cRParenLoc);
76+
}
77+
78+
BridgedDeclNameLoc BridgedDeclNameLoc_createParsed(
79+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
80+
BridgedSourceLoc cBaseNameLoc, BridgedSourceLoc cLParenLoc,
81+
BridgedArrayRef cLabelLocs, BridgedSourceLoc cRParenLoc) {
7382

7483
ASTContext &context = cContext.unbridged();
7584
SmallVector<SourceLoc, 4> labelLocs;
7685
for (auto &cLabelLoc : cLabelLocs.unbridged<BridgedSourceLoc>())
7786
labelLocs.push_back(cLabelLoc.unbridged());
7887

79-
return DeclNameLoc(context, cBaseNameLoc.unbridged(), cLParenLoc.unbridged(),
88+
return DeclNameLoc(context, cModuleSelectorLoc.unbridged(),
89+
cBaseNameLoc.unbridged(), cLParenLoc.unbridged(),
8090
labelLocs, cRParenLoc.unbridged());
8191
}
8292

@@ -85,6 +95,14 @@ BridgedDeclNameLoc_createParsed(BridgedSourceLoc cBaseNameLoc) {
8595
return DeclNameLoc(cBaseNameLoc.unbridged());
8696
}
8797

98+
BridgedDeclNameLoc
99+
BridgedDeclNameLoc_createParsed(
100+
BridgedASTContext cContext, BridgedSourceLoc cModuleSelectorLoc,
101+
BridgedSourceLoc cBaseNameLoc) {
102+
return DeclNameLoc(cContext.unbridged(), cModuleSelectorLoc.unbridged(),
103+
cBaseNameLoc.unbridged());
104+
}
105+
88106
//===----------------------------------------------------------------------===//
89107
// MARK: Decls
90108
//===----------------------------------------------------------------------===//

lib/AST/Identifier.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ void swift::simple_display(llvm::raw_ostream &out, DeclName name) {
5555
}
5656

5757
raw_ostream &llvm::operator<<(raw_ostream &OS, DeclNameRef I) {
58+
if (I.hasModuleSelector())
59+
OS << I.getModuleSelector() << "::";
5860
OS << I.getFullName();
5961
return OS;
6062
}
@@ -208,17 +210,27 @@ void DeclNameRef::dump() const {
208210
}
209211

210212
StringRef DeclNameRef::getString(llvm::SmallVectorImpl<char> &scratch,
211-
bool skipEmptyArgumentNames) const {
212-
return FullName.getString(scratch, skipEmptyArgumentNames);
213+
bool skipEmptyArgumentNames) const {
214+
{
215+
llvm::raw_svector_ostream out(scratch);
216+
print(out, skipEmptyArgumentNames);
217+
}
218+
219+
return StringRef(scratch.data(), scratch.size());
213220
}
214221

215-
llvm::raw_ostream &DeclNameRef::print(llvm::raw_ostream &os,
216-
bool skipEmptyArgumentNames) const {
217-
return FullName.print(os, skipEmptyArgumentNames);
222+
llvm::raw_ostream &
223+
DeclNameRef::print(llvm::raw_ostream &os,
224+
bool skipEmptyArgumentNames) const {
225+
if (hasModuleSelector())
226+
os << getModuleSelector() << "::";
227+
return getFullName().print(os, skipEmptyArgumentNames);
218228
}
219229

220230
llvm::raw_ostream &DeclNameRef::printPretty(llvm::raw_ostream &os) const {
221-
return FullName.printPretty(os);
231+
if (hasModuleSelector())
232+
os << getModuleSelector() << "::";
233+
return getFullName().printPretty(os);
222234
}
223235

224236
ObjCSelector::ObjCSelector(ASTContext &ctx, unsigned numArgs,

lib/Parse/ParseExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,15 +2291,15 @@ DeclNameRef Parser::parseDeclNameRef(DeclNameLoc &loc,
22912291
rparenLoc);
22922292

22932293
if (argumentLabelLocs.empty() || !hadArgList)
2294-
loc = DeclNameLoc(baseNameLoc);
2294+
loc = DeclNameLoc(Context, moduleSelectorLoc, baseNameLoc);
22952295
else
2296-
loc = DeclNameLoc(Context, baseNameLoc, lparenLoc, argumentLabelLocs,
2297-
rparenLoc);
2296+
loc = DeclNameLoc(Context, moduleSelectorLoc, baseNameLoc,
2297+
lparenLoc, argumentLabelLocs, rparenLoc);
22982298

22992299
if (!hadArgList)
2300-
return DeclNameRef(baseName);
2300+
return DeclNameRef(Context, moduleSelector, baseName);
23012301

2302-
return DeclNameRef({ Context, baseName, argumentLabels });
2302+
return DeclNameRef(Context, moduleSelector, baseName, argumentLabels);
23032303
}
23042304

23052305
ParserStatus Parser::parseFreestandingMacroExpansion(

0 commit comments

Comments
 (0)