aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/APINotes
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2020-11-05 23:59:39 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2020-11-23 21:29:17 +0000
commitf6b02ecd027a825f1f4a1804c464f9f96d9372c9 (patch)
treed98824a9ef3a6e913d314e7b4c45026895f73118 /clang/lib/APINotes
parent6a2799cf8ecf1b649cfa511aec64256a01f79436 (diff)
downloadllvm-f6b02ecd027a825f1f4a1804c464f9f96d9372c9.zip
llvm-f6b02ecd027a825f1f4a1804c464f9f96d9372c9.tar.gz
llvm-f6b02ecd027a825f1f4a1804c464f9f96d9372c9.tar.bz2
APINotes: add property models for YAML attributes
This adds internal representation of the attributes in a more usable form. This is meant to allow programmatic access to the attributes that are specified in the YAML data. This is based upon the work contributed by Apple at https://github.com/llvm/llvm-project-staging/tree/staging/swift/apinotes. Differential Revision: https://reviews.llvm.org/D91104 Reviewed By: Gabor Marton
Diffstat (limited to 'clang/lib/APINotes')
-rw-r--r--clang/lib/APINotes/APINotesTypes.cpp107
-rw-r--r--clang/lib/APINotes/CMakeLists.txt1
2 files changed, 108 insertions, 0 deletions
diff --git a/clang/lib/APINotes/APINotesTypes.cpp b/clang/lib/APINotes/APINotesTypes.cpp
new file mode 100644
index 0000000..f443d90
--- /dev/null
+++ b/clang/lib/APINotes/APINotesTypes.cpp
@@ -0,0 +1,107 @@
+//===-- APINotesTypes.cpp - API Notes Data Types ----------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/APINotes/Types.h"
+#include "llvm/Support/raw_ostream.h"
+
+namespace clang {
+namespace api_notes {
+void CommonEntityInfo::dump(llvm::raw_ostream &OS) {
+ if (Unavailable)
+ OS << "[Unavailable] (" << UnavailableMsg << ")" << ' ';
+ if (UnavailableInSwift)
+ OS << "[UnavailableInSwift] ";
+ if (SwiftPrivateSpecified)
+ OS << (SwiftPrivate ? "[SwiftPrivate] " : "");
+ if (!SwiftName.empty())
+ OS << "Swift Name: " << SwiftName << ' ';
+ OS << '\n';
+}
+
+void CommonTypeInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonEntityInfo &>(*this).dump(OS);
+ if (SwiftBridge)
+ OS << "Swift Briged Type: " << *SwiftBridge << ' ';
+ if (NSErrorDomain)
+ OS << "NSError Domain: " << *NSErrorDomain << ' ';
+ OS << '\n';
+}
+
+void ObjCContextInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonTypeInfo &>(*this).dump(OS);
+ if (HasDefaultNullability)
+ OS << "DefaultNullability: " << DefaultNullability << ' ';
+ if (HasDesignatedInits)
+ OS << "[HasDesignatedInits] ";
+ if (SwiftImportAsNonGenericSpecified)
+ OS << (SwiftImportAsNonGeneric ? "[SwiftImportAsNonGeneric] " : "");
+ if (SwiftObjCMembersSpecified)
+ OS << (SwiftObjCMembers ? "[SwiftObjCMembers] " : "");
+ OS << '\n';
+}
+
+void VariableInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonEntityInfo &>(*this).dump(OS);
+ if (NullabilityAudited)
+ OS << "Audited Nullability: " << Nullable << ' ';
+ if (!Type.empty())
+ OS << "C Type: " << Type << ' ';
+ OS << '\n';
+}
+
+void ObjCPropertyInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<VariableInfo &>(*this).dump(OS);
+ if (SwiftImportAsAccessorsSpecified)
+ OS << (SwiftImportAsAccessors ? "[SwiftImportAsAccessors] " : "");
+ OS << '\n';
+}
+
+void ParamInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<VariableInfo &>(*this).dump(OS);
+ if (NoEscapeSpecified)
+ OS << (NoEscape ? "[NoEscape] " : "");
+ OS << "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
+ OS << '\n';
+}
+
+void FunctionInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonEntityInfo &>(*this).dump(OS);
+ OS << (NullabilityAudited ? "[NullabilityAudited] " : "")
+ << "RawRetainCountConvention: " << RawRetainCountConvention << ' ';
+ if (!ResultType.empty())
+ OS << "Result Type: " << ResultType << ' ';
+ if (!Params.empty())
+ OS << '\n';
+ for (auto &PI : Params)
+ PI.dump(OS);
+}
+
+void ObjCMethodInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<FunctionInfo &>(*this).dump(OS);
+ OS << (DesignatedInit ? "[DesignatedInit] " : "")
+ << (RequiredInit ? "[RequiredInit] " : "") << '\n';
+}
+
+void TagInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonTypeInfo &>(*this).dump(OS);
+ if (HasFlagEnum)
+ OS << (IsFlagEnum ? "[FlagEnum] " : "");
+ if (EnumExtensibility)
+ OS << "Enum Extensibility: " << static_cast<long>(*EnumExtensibility)
+ << ' ';
+ OS << '\n';
+}
+
+void TypedefInfo::dump(llvm::raw_ostream &OS) {
+ static_cast<CommonTypeInfo &>(*this).dump(OS);
+ if (SwiftWrapper)
+ OS << "Swift Type: " << static_cast<long>(*SwiftWrapper) << ' ';
+ OS << '\n';
+}
+} // namespace api_notes
+} // namespace clang
diff --git a/clang/lib/APINotes/CMakeLists.txt b/clang/lib/APINotes/CMakeLists.txt
index 3ce511a..3fd0e97 100644
--- a/clang/lib/APINotes/CMakeLists.txt
+++ b/clang/lib/APINotes/CMakeLists.txt
@@ -1,6 +1,7 @@
set(LLVM_LINK_COMPONENTS
Support)
add_clang_library(clangAPINotes
+ APINotesTypes.cpp
APINotesYAMLCompiler.cpp
LINK_LIBS
clangBasic)