clang 24.0.0git
SemaAPINotesInternal.h
Go to the documentation of this file.
1//===--- SemaAPINotesInternal.h - API Notes Sema Internals ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_LIB_SEMA_SEMAAPINOTESINTERNAL_H
10#define LLVM_CLANG_LIB_SEMA_SEMAAPINOTESINTERNAL_H
11
14#include "llvm/ADT/ArrayRef.h"
15#include "llvm/ADT/DenseMap.h"
16#include "llvm/ADT/STLFunctionalExtras.h"
17#include "llvm/ADT/SmallVector.h"
18#include "llvm/ADT/StringRef.h"
19#include <string>
20#include <utility>
21
22namespace clang {
23class Sema;
25namespace api_notes {
26class APINotesReader;
27} // namespace api_notes
28
29/// Source name and location for a declaration seen by Sema.
34
35/// Tracks exact Where.Parameters selectors from one API notes reader.
36///
37/// Sema marks selectors as used when a visible declaration matches them. It
38/// also records broad/name-only declarations seen in the translation unit, so
39/// end-of-TU diagnostics can warn about exact selectors for known names that
40/// were never matched.
42 /// Exact Where.Parameters selector keys stored by API notes. The bool is
43 /// true once Sema sees a declaration matching the exact selector.
44 llvm::DenseMap<api_notes::APINotesFunctionSelectorKey, bool> SelectorUsed;
45
46 /// Maps broad/name-only keys to a declaration location/name used for
47 /// diagnostics.
51
53 SelectorUsed.try_emplace(Key, false);
54 }
55
58 SelectorUsed.reserve(Selectors.size());
59 SeenNames.reserve(Selectors.size());
60 for (const auto &Selector : Selectors)
62 }
63
65 llvm::StringRef Name, SourceLocation Loc) {
66 SeenNames.insert({Key.getWithoutParameterSelector(), {Loc, Name.str()}});
67 }
68
70 auto KnownSelector = SelectorUsed.find(Key);
71 if (KnownSelector != SelectorUsed.end())
72 KnownSelector->second = true;
73 }
74
76 llvm::function_ref<std::optional<api_notes::APINotesFunctionSelectorKey>(
78 GetSelectorKey,
79 const APINotesParameterSelectorCandidates &Candidates);
80
81 void diagnoseUnused(Sema &S, api_notes::APINotesReader &Reader) const;
82};
83
84/// Selector diagnostic state for all API notes readers used by one Sema.
95
96} // namespace clang
97
98#endif // LLVM_CLANG_LIB_SEMA_SEMAAPINOTESINTERNAL_H
Defines the clang::SourceLocation class and associated facilities.
Smart pointer class that efficiently represents Objective-C method names.
Sema - This implements semantic analysis and AST building for C.
Definition Sema.h:869
Encodes a location in the source.
A class that reads API notes data from a binary file that was written by the APINotesWriter.
The JSON file list parser is used to communicate input to InstallAPI.
Source name and location for a declaration seen by Sema.
Tracks exact Where.Parameters selectors from one API notes reader.
void markUsed(const api_notes::APINotesFunctionSelectorKey &Key)
void diagnoseUnused(Sema &S, api_notes::APINotesReader &Reader) const
llvm::DenseMap< api_notes::APINotesFunctionSelectorKey, bool > SelectorUsed
Exact Where.Parameters selector keys stored by API notes.
void noteSeenDeclaration(const api_notes::APINotesFunctionSelectorKey &Key, llvm::StringRef Name, SourceLocation Loc)
void markCandidatesUsed(llvm::function_ref< std::optional< api_notes::APINotesFunctionSelectorKey >(llvm::ArrayRef< std::string >)> GetSelectorKey, const APINotesParameterSelectorCandidates &Candidates)
llvm::DenseMap< api_notes::APINotesFunctionSelectorKey, APINotesSelectorDiagnosticName > SeenNames
Maps broad/name-only keys to a declaration location/name used for diagnostics.
void addSelectors(llvm::ArrayRef< api_notes::APINotesFunctionSelectorKey > Selectors)
void addSelector(const api_notes::APINotesFunctionSelectorKey &Key)
Selector diagnostic state for all API notes readers used by one Sema.
APINotesSelectorDiagnosticReaderState & getOrCreateReaderState(api_notes::APINotesReader &Reader)
llvm::DenseMap< api_notes::APINotesReader *, APINotesSelectorDiagnosticReaderState > Readers
Stable reader-facing identity for an API notes function selector entry.
Definition Types.h:1068
APINotesFunctionSelectorKey getWithoutParameterSelector() const
Definition Types.h:1072