Skip to content

Commit

Permalink
[Tooling/Inclusion] Make the Recognizer work for C99 code.
Browse files Browse the repository at this point in the history
C99 is the the earliest C version provided by the language opt.

Differential Revision: https://reviews.llvm.org/D155816
  • Loading branch information
hokein committed Jul 25, 2023
1 parent 5986559 commit e93cbd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 3 additions & 4 deletions clang/lib/Tooling/Inclusions/Stdlib/StandardLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,12 @@ NSSymbolMap *Recognizer::namespaceSymbols(const DeclContext *DC, Lang L) {

std::optional<Symbol> Recognizer::operator()(const Decl *D) {
Lang L;
if (D->getLangOpts().CPlusPlus) {
if (D->getLangOpts().CPlusPlus)
L = Lang::CXX;
} else if (D->getLangOpts().C11) {
else if (D->getLangOpts().C99)
L = Lang::C;
} else {
else
return std::nullopt; // not a supported language.
}

// If D is std::vector::iterator, `vector` is the outer symbol to look up.
// We keep all the candidate DCs as some may turn out to be anon enums.
Expand Down
11 changes: 11 additions & 0 deletions clang/unittests/Tooling/StandardLibraryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@ TEST(StdlibTest, Recognizer) {
EXPECT_EQ(Recognizer(Sec), std::nullopt);
}

TEST(StdlibTest, RecognizerForC99) {
TestInputs Input("typedef char uint8_t;");
Input.Language = TestLanguage::Lang_C99;
TestAST AST(Input);

auto &Uint8T = lookup(AST, "uint8_t");
stdlib::Recognizer Recognizer;
EXPECT_EQ(Recognizer(&Uint8T),
stdlib::Symbol::named("", "uint8_t", stdlib::Lang::C));
}

} // namespace
} // namespace tooling
} // namespace clang

0 comments on commit e93cbd1

Please sign in to comment.