clang 19.0.0git
API.cpp
Go to the documentation of this file.
1//===- ExtractAPI/API.cpp ---------------------------------------*- 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/// \file
10/// This file implements the APIRecord and derived record structs,
11/// and the APISet class.
12///
13//===----------------------------------------------------------------------===//
14
17#include "clang/Basic/Module.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/ErrorHandling.h"
21#include <memory>
22
23using namespace clang::extractapi;
24using namespace llvm;
25
27 : Name(R->Name), USR(R->USR), Record(R) {}
28
30 switch (Ctx->getKind()) {
31#define RECORD_CONTEXT(CLASS, KIND) \
32 case KIND: \
33 return static_cast<CLASS *>(const_cast<RecordContext *>(Ctx));
35 default:
36 return nullptr;
37 // llvm_unreachable("RecordContext derived class isn't propertly
38 // implemented");
39 }
40}
41
43 if (!Record)
44 return nullptr;
45 switch (Record->getKind()) {
46#define RECORD_CONTEXT(CLASS, KIND) \
47 case KIND: \
48 return static_cast<CLASS *>(const_cast<APIRecord *>(Record));
50 default:
51 return nullptr;
52 // llvm_unreachable("RecordContext derived class isn't propertly
53 // implemented");
54 }
55}
56
58 if (!First) {
59 First = Record;
60 Last = Record;
61 return;
62 }
63
64 Last->NextInContext = Record;
65 Last = Record;
66}
67
68APIRecord *APISet::findRecordForUSR(StringRef USR) const {
69 if (USR.empty())
70 return nullptr;
71
72 auto FindIt = USRBasedLookupTable.find(USR);
73 if (FindIt != USRBasedLookupTable.end())
74 return FindIt->getSecond().get();
75
76 return nullptr;
77}
78
79StringRef APISet::copyString(StringRef String) {
80 if (String.empty())
81 return {};
82
83 // No need to allocate memory and copy if the string has already been stored.
84 if (Allocator.identifyObject(String.data()))
85 return String;
86
87 void *Ptr = Allocator.Allocate(String.size(), 1);
88 memcpy(Ptr, String.data(), String.size());
89 return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
90}
91
92SymbolReference APISet::createSymbolReference(StringRef Name, StringRef USR,
93 StringRef Source) {
94 return SymbolReference(copyString(Name), copyString(USR), copyString(Source));
95}
96
100ObjCContainerRecord::~ObjCContainerRecord() {}
104
105void GlobalFunctionRecord::anchor() {}
106void GlobalVariableRecord::anchor() {}
107void EnumConstantRecord::anchor() {}
108void EnumRecord::anchor() {}
109void StructFieldRecord::anchor() {}
110void StructRecord::anchor() {}
111void UnionFieldRecord::anchor() {}
112void UnionRecord::anchor() {}
113void CXXFieldRecord::anchor() {}
114void CXXClassRecord::anchor() {}
115void CXXConstructorRecord::anchor() {}
116void CXXDestructorRecord::anchor() {}
117void CXXInstanceMethodRecord::anchor() {}
118void CXXStaticMethodRecord::anchor() {}
119void ObjCInstancePropertyRecord::anchor() {}
120void ObjCClassPropertyRecord::anchor() {}
121void ObjCInstanceVariableRecord::anchor() {}
122void ObjCInstanceMethodRecord::anchor() {}
123void ObjCClassMethodRecord::anchor() {}
124void ObjCCategoryRecord::anchor() {}
125void ObjCInterfaceRecord::anchor() {}
126void ObjCProtocolRecord::anchor() {}
127void MacroDefinitionRecord::anchor() {}
128void TypedefRecord::anchor() {}
This file defines the APIRecord-based structs and the APISet class.
llvm::MachO::Record Record
Definition: MachO.h:31
Defines the clang::Module class, which describes a module in the source code.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
SymbolReference createSymbolReference(StringRef Name, StringRef USR, StringRef Source="")
Definition: API.cpp:92
StringRef copyString(StringRef String)
Copy String into the Allocator in this APISet.
Definition: API.cpp:79
APIRecord * findRecordForUSR(StringRef USR) const
Finds the APIRecord for a given USR.
Definition: API.cpp:68
Base class used for specific record types that have children records this is analogous to the DeclCon...
Definition: API.h:310
APIRecord::RecordKind getKind() const
Definition: API.h:324
void addToRecordChain(APIRecord *) const
Definition: API.cpp:57
Diagnostic wrappers for TextAPI types for error reporting.
Definition: Dominators.h:30
The base representation of an API record. Holds common symbol information.
Definition: API.h:192
virtual ~APIRecord()=0
Definition: API.cpp:97
static APIRecord * castFromRecordContext(const RecordContext *Ctx)
Definition: API.cpp:29
static RecordContext * castToRecordContext(const APIRecord *Record)
Definition: API.cpp:42