Skip to content

Commit a53b6ab

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

File tree

4 files changed

+65
-32
lines changed

4 files changed

+65
-32
lines changed

include/swift/AST/DeclNameLoc.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,24 @@ class DeclNameLoc {
6565
: LocationInfo(baseNameLoc.getOpaquePointerValue()),
6666
NumArgumentLabels(0) { }
6767

68+
explicit DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
69+
SourceLoc baseNameLoc)
70+
: DeclNameLoc(baseNameLoc) { }
71+
6872
/// Create declaration name location information for a compound
6973
/// name.
7074
DeclNameLoc(ASTContext &ctx, SourceLoc baseNameLoc,
7175
SourceLoc lParenLoc,
7276
ArrayRef<SourceLoc> argumentLabelLocs,
7377
SourceLoc rParenLoc);
7478

79+
DeclNameLoc(ASTContext &ctx, SourceLoc moduleSelectorLoc,
80+
SourceLoc baseNameLoc,
81+
SourceLoc lParenLoc,
82+
ArrayRef<SourceLoc> argumentLabelLocs,
83+
SourceLoc rParenLoc)
84+
: DeclNameLoc(ctx, baseNameLoc, lParenLoc, argumentLabelLocs, rParenLoc) { }
85+
7586
/// Whether the location information is valid.
7687
bool isValid() const { return getBaseNameLoc().isValid(); }
7788

@@ -105,6 +116,10 @@ class DeclNameLoc {
105116
return getSourceLocs()[FirstArgumentLabelIndex + index];
106117
}
107118

119+
SourceLoc getModuleSelectorLoc() const {
120+
return SourceLoc();
121+
}
122+
108123
SourceLoc getStartLoc() const {
109124
return getBaseNameLoc();
110125
}

include/swift/AST/Identifier.h

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -651,63 +651,69 @@ class DeclNameRef {
651651
void *getOpaqueValue() const { return FullName.getOpaqueValue(); }
652652
static DeclNameRef getFromOpaqueValue(void *p);
653653

654-
explicit DeclNameRef(DeclName FullName)
655-
: FullName(FullName) { }
654+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
655+
DeclName fullName)
656+
: FullName(fullName) { }
656657

657-
explicit DeclNameRef(DeclBaseName BaseName)
658-
: FullName(BaseName) { }
658+
explicit DeclNameRef(ASTContext &C, Identifier moduleSelector,
659+
DeclBaseName baseName, ArrayRef<Identifier> argLabels)
660+
: FullName(C, baseName, argLabels) { }
659661

660-
explicit DeclNameRef(Identifier BaseName)
662+
explicit DeclNameRef(DeclName FullName)
661663
: FullName(BaseName) { }
662664

663-
/// The name of the declaration being referenced.
664-
DeclName getFullName() const {
665-
return FullName;
665+
bool hasModuleSelector() const {
666+
return false;
667+
}
668+
669+
Identifier getModuleSelector() const {
670+
return Identifier();
666671
}
667672

668-
DeclName &getFullName() {
673+
/// The name of the declaration being referenced.
674+
DeclName getFullName() const {
669675
return FullName;
670676
}
671677

672678
/// The base name of the declaration being referenced.
673679
DeclBaseName getBaseName() const {
674-
return FullName.getBaseName();
680+
return getFullName().getBaseName();
675681
}
676682

677683
Identifier getBaseIdentifier() const {
678-
return FullName.getBaseIdentifier();
684+
return getFullName().getBaseIdentifier();
679685
}
680686

681687
ArrayRef<Identifier> getArgumentNames() const {
682-
return FullName.getArgumentNames();
688+
return getFullName().getArgumentNames();
683689
}
684690

685691
bool isSimpleName() const {
686-
return FullName.isSimpleName();
692+
return getFullName().isSimpleName();
687693
}
688694

689695
bool isSimpleName(DeclBaseName name) const {
690-
return FullName.isSimpleName(name);
696+
return getFullName().isSimpleName(name);
691697
}
692698

693699
bool isSimpleName(StringRef name) const {
694-
return FullName.isSimpleName(name);
700+
return getFullName().isSimpleName(name);
695701
}
696702

697703
bool isSpecial() const {
698-
return FullName.isSpecial();
704+
return getFullName().isSpecial();
699705
}
700706

701707
bool isOperator() const {
702-
return FullName.isOperator();
708+
return getFullName().isOperator();
703709
}
704710

705711
bool isCompoundName() const {
706-
return FullName.isCompoundName();
712+
return getFullName().isCompoundName();
707713
}
708714

709715
explicit operator bool() const {
710-
return (bool)FullName;
716+
return (bool)getFullName();
711717
}
712718

713719
/// Compare two declaration names, producing -1 if \c *this comes before
@@ -782,12 +788,12 @@ inline DeclNameRef DeclNameRef::getFromOpaqueValue(void *p) {
782788
}
783789

784790
inline DeclNameRef DeclNameRef::withoutArgumentLabels(ASTContext &C) const {
785-
return DeclNameRef(getBaseName());
791+
return DeclNameRef(C, getModuleSelector(), getBaseName());
786792
}
787793

788794
inline DeclNameRef DeclNameRef::withArgumentLabels(
789795
ASTContext &C, ArrayRef<Identifier> argumentNames) const {
790-
return DeclNameRef(DeclName(C, getBaseName(), argumentNames));
796+
return DeclNameRef(C, getModuleSelector(), getBaseName(), argumentNames);
791797
}
792798

793799
inline DeclNameRef DeclNameRef::createSubscript() {

lib/AST/Identifier.cpp

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

5656
raw_ostream &llvm::operator<<(raw_ostream &OS, DeclNameRef I) {
57+
if (I.hasModuleSelector())
58+
OS << I.getModuleSelector() << "::";
5759
OS << I.getFullName();
5860
return OS;
5961
}
@@ -205,17 +207,27 @@ void DeclNameRef::dump() const {
205207
}
206208

207209
StringRef DeclNameRef::getString(llvm::SmallVectorImpl<char> &scratch,
208-
bool skipEmptyArgumentNames) const {
209-
return FullName.getString(scratch, skipEmptyArgumentNames);
210+
bool skipEmptyArgumentNames) const {
211+
{
212+
llvm::raw_svector_ostream out(scratch);
213+
print(out, skipEmptyArgumentNames);
214+
}
215+
216+
return StringRef(scratch.data(), scratch.size());
210217
}
211218

212-
llvm::raw_ostream &DeclNameRef::print(llvm::raw_ostream &os,
213-
bool skipEmptyArgumentNames) const {
214-
return FullName.print(os, skipEmptyArgumentNames);
219+
llvm::raw_ostream &
220+
DeclNameRef::print(llvm::raw_ostream &os,
221+
bool skipEmptyArgumentNames) const {
222+
if (hasModuleSelector())
223+
os << getModuleSelector() << "::";
224+
return getFullName().print(os, skipEmptyArgumentNames);
215225
}
216226

217227
llvm::raw_ostream &DeclNameRef::printPretty(llvm::raw_ostream &os) const {
218-
return FullName.printPretty(os);
228+
if (hasModuleSelector())
229+
os << getModuleSelector() << "::";
230+
return getFullName().printPretty(os);
219231
}
220232

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

lib/Parse/ParseExpr.cpp

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

23552355
if (argumentLabelLocs.empty() || !hadArgList)
2356-
loc = DeclNameLoc(baseNameLoc);
2356+
loc = DeclNameLoc(Context, moduleSelectorLoc, baseNameLoc);
23572357
else
2358-
loc = DeclNameLoc(Context, baseNameLoc, lparenLoc, argumentLabelLocs,
2359-
rparenLoc);
2358+
loc = DeclNameLoc(Context, moduleSelectorLoc, baseNameLoc,
2359+
lparenLoc, argumentLabelLocs, rparenLoc);
23602360

23612361
if (!hadArgList)
2362-
return DeclNameRef(baseName);
2362+
return DeclNameRef(Context, moduleSelector, baseName);
23632363

2364-
return DeclNameRef({ Context, baseName, argumentLabels });
2364+
return DeclNameRef(Context, moduleSelector, baseName, argumentLabels);
23652365
}
23662366

23672367
/// expr-identifier:

0 commit comments

Comments
 (0)