Skip to content

Commit 5ef0e85

Browse files
committed
[APINotes] NFC: refactor, make context params optional
rdar://114382260
1 parent ea634ac commit 5ef0e85

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

clang/include/clang/APINotes/APINotesReader.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,17 @@ class APINotesReader {
176176
///
177177
/// \returns information about the global variable, if known.
178178
VersionedInfo<GlobalVariableInfo>
179-
lookupGlobalVariable(std::optional<Context> context, llvm::StringRef name);
179+
lookupGlobalVariable(llvm::StringRef name,
180+
std::optional<Context> context = std::nullopt);
180181

181182
/// Look for information regarding the given global function.
182183
///
183184
/// \param name The name of the global function.
184185
///
185186
/// \returns information about the global function, if known.
186187
VersionedInfo<GlobalFunctionInfo>
187-
lookupGlobalFunction(std::optional<Context> context, llvm::StringRef name);
188+
lookupGlobalFunction(llvm::StringRef name,
189+
std::optional<Context> context = std::nullopt);
188190

189191
/// Look for information regarding the given enumerator.
190192
///
@@ -199,25 +201,27 @@ class APINotesReader {
199201
/// \param name The name of the tag.
200202
///
201203
/// \returns information about the tag, if known.
202-
VersionedInfo<TagInfo> lookupTag(std::optional<Context> context,
203-
llvm::StringRef name);
204+
VersionedInfo<TagInfo>
205+
lookupTag(llvm::StringRef name,
206+
std::optional<Context> context = std::nullopt);
204207

205208
/// Look for information regarding the given typedef.
206209
///
207210
/// \param name The name of the typedef.
208211
///
209212
/// \returns information about the typedef, if known.
210-
VersionedInfo<TypedefInfo> lookupTypedef(std::optional<Context> context,
211-
llvm::StringRef name);
213+
VersionedInfo<TypedefInfo>
214+
lookupTypedef(llvm::StringRef name,
215+
std::optional<Context> context = std::nullopt);
212216

213217
/// Look for the context ID of the given C++ namespace.
214218
///
215219
/// \param name The name of the class we're looking for.
216220
///
217221
/// \returns The ID, if known.
218222
llvm::Optional<ContextID>
219-
lookupNamespaceID(llvm::Optional<ContextID> parentNamespaceID,
220-
llvm::StringRef name);
223+
lookupNamespaceID(llvm::StringRef name,
224+
llvm::Optional<ContextID> parentNamespaceID = llvm::None);
221225
};
222226

223227
} // end namespace api_notes

clang/lib/APINotes/APINotesReader.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,8 +1961,8 @@ auto APINotesReader::lookupObjCMethod(
19611961
return { Impl.SwiftVersion, *known };
19621962
}
19631963

1964-
auto APINotesReader::lookupGlobalVariable(std::optional<Context> context,
1965-
StringRef name)
1964+
auto APINotesReader::lookupGlobalVariable(StringRef name,
1965+
std::optional<Context> context)
19661966
-> VersionedInfo<GlobalVariableInfo> {
19671967
if (!Impl.GlobalVariableTable)
19681968
return None;
@@ -1980,8 +1980,8 @@ auto APINotesReader::lookupGlobalVariable(std::optional<Context> context,
19801980
return { Impl.SwiftVersion, *known };
19811981
}
19821982

1983-
auto APINotesReader::lookupGlobalFunction(std::optional<Context> context,
1984-
StringRef name)
1983+
auto APINotesReader::lookupGlobalFunction(StringRef name,
1984+
std::optional<Context> context)
19851985
-> VersionedInfo<GlobalFunctionInfo> {
19861986
if (!Impl.GlobalFunctionTable)
19871987
return None;
@@ -2015,7 +2015,7 @@ auto APINotesReader::lookupEnumConstant(StringRef name)
20152015
return { Impl.SwiftVersion, *known };
20162016
}
20172017

2018-
auto APINotesReader::lookupTag(std::optional<Context> context, StringRef name)
2018+
auto APINotesReader::lookupTag(StringRef name, std::optional<Context> context)
20192019
-> VersionedInfo<TagInfo> {
20202020
if (!Impl.TagTable)
20212021
return None;
@@ -2033,8 +2033,8 @@ auto APINotesReader::lookupTag(std::optional<Context> context, StringRef name)
20332033
return { Impl.SwiftVersion, *known };
20342034
}
20352035

2036-
auto APINotesReader::lookupTypedef(std::optional<Context> context,
2037-
StringRef name)
2036+
auto APINotesReader::lookupTypedef(StringRef name,
2037+
std::optional<Context> context)
20382038
-> VersionedInfo<TypedefInfo> {
20392039
if (!Impl.TypedefTable)
20402040
return None;
@@ -2053,7 +2053,7 @@ auto APINotesReader::lookupTypedef(std::optional<Context> context,
20532053
}
20542054

20552055
auto APINotesReader::lookupNamespaceID(
2056-
Optional<ContextID> parentNamespaceID, StringRef name)
2056+
StringRef name, Optional<ContextID> parentNamespaceID)
20572057
-> Optional<ContextID> {
20582058
if (!Impl.ObjCContextIDTable)
20592059
return None;

clang/lib/Sema/SemaAPINotes.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -822,20 +822,19 @@ void Sema::ProcessAPINotes(Decl *D) {
822822
// Retrieve the context ID for the parent namespace of the decl.
823823
std::stack<NamespaceDecl *> NamespaceStack;
824824
{
825-
auto CurrentNamespace = NamespaceContext;
826-
while (CurrentNamespace) {
825+
for (auto CurrentNamespace = NamespaceContext; CurrentNamespace;
826+
CurrentNamespace =
827+
dyn_cast<NamespaceDecl>(CurrentNamespace->getParent())) {
827828
if (!CurrentNamespace->isInlineNamespace())
828829
NamespaceStack.push(CurrentNamespace);
829-
CurrentNamespace =
830-
dyn_cast<NamespaceDecl>(CurrentNamespace->getParent());
831830
}
832831
}
833832
Optional<api_notes::ContextID> NamespaceID;
834833
while (!NamespaceStack.empty()) {
835834
auto CurrentNamespace = NamespaceStack.top();
836835
NamespaceStack.pop();
837-
NamespaceID = Reader->lookupNamespaceID(NamespaceID,
838-
CurrentNamespace->getName());
836+
NamespaceID = Reader->lookupNamespaceID(CurrentNamespace->getName(),
837+
NamespaceID);
839838
if (!NamespaceID)
840839
break;
841840
}
@@ -849,7 +848,7 @@ void Sema::ProcessAPINotes(Decl *D) {
849848
if (auto VD = dyn_cast<VarDecl>(D)) {
850849
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
851850
auto Info =
852-
Reader->lookupGlobalVariable(APINotesContext, VD->getName());
851+
Reader->lookupGlobalVariable(VD->getName(), APINotesContext);
853852
ProcessVersionedAPINotes(*this, VD, Info);
854853
}
855854

@@ -861,7 +860,7 @@ void Sema::ProcessAPINotes(Decl *D) {
861860
if (FD->getDeclName().isIdentifier()) {
862861
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
863862
auto Info =
864-
Reader->lookupGlobalFunction(APINotesContext, FD->getName());
863+
Reader->lookupGlobalFunction(FD->getName(), APINotesContext);
865864
ProcessVersionedAPINotes(*this, FD, Info);
866865
}
867866
}
@@ -916,7 +915,7 @@ void Sema::ProcessAPINotes(Decl *D) {
916915
}
917916

918917
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
919-
auto Info = Reader->lookupTag(APINotesContext, LookupName);
918+
auto Info = Reader->lookupTag(LookupName, APINotesContext);
920919
ProcessVersionedAPINotes(*this, Tag, Info);
921920
}
922921

@@ -926,7 +925,7 @@ void Sema::ProcessAPINotes(Decl *D) {
926925
// Typedefs
927926
if (auto Typedef = dyn_cast<TypedefNameDecl>(D)) {
928927
for (auto Reader : APINotes.findAPINotes(D->getLocation())) {
929-
auto Info = Reader->lookupTypedef(APINotesContext, Typedef->getName());
928+
auto Info = Reader->lookupTypedef(Typedef->getName(), APINotesContext);
930929
ProcessVersionedAPINotes(*this, Typedef, Info);
931930
}
932931

0 commit comments

Comments
 (0)