clang 23.0.0git
TUSummaryExtractor.cpp
Go to the documentation of this file.
1//===- TUSummaryExtractor.cpp ---------------------------------------------===//
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
10#include "clang/AST/Decl.h"
15#include <optional>
16
17using namespace clang;
18using namespace ssaf;
19
21 const auto *ND = dyn_cast<NamedDecl>(D);
22 if (!ND)
23 return EntityLinkageType::None;
24
25 switch (ND->getFormalLinkage()) {
26 case Linkage::Invalid: {
27 llvm_unreachable("Shouldn't be invalid");
28 }
29 case Linkage::None:
30 return EntityLinkageType::None;
32 return EntityLinkageType::Internal;
34 return EntityLinkageType::Internal;
36 return EntityLinkageType::Internal;
37 case Linkage::Module:
38 return EntityLinkageType::External;
40 return EntityLinkageType::External;
41 }
42 llvm_unreachable("Unhandled clang::Linkage kind");
43}
44
45std::optional<EntityId> TUSummaryExtractor::addEntity(const NamedDecl *D) {
46 auto Name = getEntityName(D);
47 if (!Name)
48 return std::nullopt;
49 return SummaryBuilder.addEntity(*Name, getLinkageForDecl(D));
50}
51
52std::optional<EntityId>
54 auto Name = getEntityNameForReturn(FD);
55 if (!Name)
56 return std::nullopt;
57 return SummaryBuilder.addEntity(*Name, getLinkageForDecl(FD));
58}
static EntityLinkageType getLinkageForDecl(const Decl *D)
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
Represents a function declaration or definition.
Definition Decl.h:2018
This represents a decl that may have a name.
Definition Decl.h:274
std::optional< EntityId > addEntityForReturn(const FunctionDecl *FD)
Creates EntityName for the return value of FD, registers the entity, and sets its linkage atomically.
std::optional< EntityId > addEntity(const NamedDecl *D)
Creates EntityName from the Decl, registers the entity, and sets its linkage atomically.
std::optional< EntityName > getEntityNameForReturn(const FunctionDecl *FD)
Maps return entity of a function to an EntityName.
std::optional< EntityName > getEntityName(const Decl *D)
Maps a declaration to an EntityName.
The JSON file list parser is used to communicate input to InstallAPI.
@ VisibleNone
No linkage according to the standard, but is visible from other translation units because of types de...
Definition Linkage.h:48
@ None
No linkage, which means that the entity is unique and can only be referred to from within its scope.
Definition Linkage.h:30
@ UniqueExternal
External linkage within a unique namespace.
Definition Linkage.h:44
@ Internal
Internal linkage, which indicates that the entity can be referred to from within the translation unit...
Definition Linkage.h:35
@ External
External linkage, which indicates that the entity can be referred to from other translation units.
Definition Linkage.h:58
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
Definition Linkage.h:54