Skip to content

Commit e6ef315

Browse files
authored
[APINotes] Introduce APINotes infrastructure in Clang Sema and Frontend
This upstreams more of the Clang API Notes functionality that is currently implemented in the Apple fork: https://github.com/apple/llvm-project/tree/next/clang/lib/APINotes This adds the initial Clang APINotes infrastructure to Clang Sema and Clang Frontend. There will shortly be a follow-up patch with the actual usages of this API. I'm splitting these changes into separate PRs to keep the diffs easier to review.
1 parent 56f5690 commit e6ef315

File tree

6 files changed

+15
-1
lines changed

6 files changed

+15
-1
lines changed

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ class CompilerInstance : public ModuleLoader {
304304
return Invocation->getHeaderSearchOptsPtr();
305305
}
306306

307+
APINotesOptions &getAPINotesOpts() { return Invocation->getAPINotesOpts(); }
308+
const APINotesOptions &getAPINotesOpts() const {
309+
return Invocation->getAPINotesOpts();
310+
}
311+
307312
LangOptions &getLangOpts() { return Invocation->getLangOpts(); }
308313
const LangOptions &getLangOpts() const { return Invocation->getLangOpts(); }
309314

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_CLANG_SEMA_SEMA_H
1515
#define LLVM_CLANG_SEMA_SEMA_H
1616

17+
#include "clang/APINotes/APINotesManager.h"
1718
#include "clang/AST/ASTConcept.h"
1819
#include "clang/AST/ASTFwd.h"
1920
#include "clang/AST/Attr.h"
@@ -408,6 +409,7 @@ class Sema final {
408409
ASTConsumer &Consumer;
409410
DiagnosticsEngine &Diags;
410411
SourceManager &SourceMgr;
412+
api_notes::APINotesManager APINotes;
411413

412414
/// Flag indicating whether or not to collect detailed statistics.
413415
bool CollectStats;

clang/lib/Frontend/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ add_clang_library(clangFrontend
4848
intrinsics_gen
4949

5050
LINK_LIBS
51+
clangAPINotes
5152
clangAST
5253
clangBasic
5354
clangDriver

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ void CompilerInstance::createSema(TranslationUnitKind TUKind,
747747
CodeCompleteConsumer *CompletionConsumer) {
748748
TheSema.reset(new Sema(getPreprocessor(), getASTContext(), getASTConsumer(),
749749
TUKind, CompletionConsumer));
750+
751+
// Set up API notes.
752+
TheSema->APINotes.setSwiftVersion(getAPINotesOpts().SwiftVersion);
753+
750754
// Attach the external sema source if there is any.
751755
if (ExternalSemaSrc) {
752756
TheSema->addExternalSource(ExternalSemaSrc.get());

clang/lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ add_clang_library(clangSema
7474
ClangDriverOptions
7575

7676
LINK_LIBS
77+
clangAPINotes
7778
clangAST
7879
clangAnalysis
7980
clangBasic

clang/lib/Sema/Sema.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
191191
: ExternalSource(nullptr), CurFPFeatures(pp.getLangOpts()),
192192
LangOpts(pp.getLangOpts()), PP(pp), Context(ctxt), Consumer(consumer),
193193
Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()),
194-
CollectStats(false), CodeCompleter(CodeCompleter), CurContext(nullptr),
194+
APINotes(SourceMgr, LangOpts), CollectStats(false),
195+
CodeCompleter(CodeCompleter), CurContext(nullptr),
195196
OriginalLexicalContext(nullptr), MSStructPragmaOn(false),
196197
MSPointerToMemberRepresentationMethod(
197198
LangOpts.getMSPointerToMemberRepresentationMethod()),

0 commit comments

Comments
 (0)