clang 20.0.0git
SemaInternal.h
Go to the documentation of this file.
1//===--- SemaInternal.h - Internal Sema Interfaces --------------*- 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// This file provides common API and #includes for the internal
10// implementation of Sema.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_SEMA_SEMAINTERNAL_H
15#define LLVM_CLANG_SEMA_SEMAINTERNAL_H
16
18#include "clang/Sema/Lookup.h"
19#include "clang/Sema/Sema.h"
21
22namespace clang {
23
24inline bool
26 return FTI.NumParams == 1 && !FTI.isVariadic &&
27 FTI.Params[0].Ident == nullptr && FTI.Params[0].Param &&
28 cast<ParmVarDecl>(FTI.Params[0].Param)->getType()->isVoidType();
29}
30
31inline bool
33 // Assume FTI is well-formed.
34 return FTI.NumParams && !FTIHasSingleVoidParameter(FTI);
35}
36
37// Helper function to check whether D's attributes match current CUDA mode.
38// Decls with mismatched attributes and related diagnostics may have to be
39// ignored during this CUDA compilation pass.
40inline bool DeclAttrsMatchCUDAMode(const LangOptions &LangOpts, Decl *D) {
41 if (!LangOpts.CUDA || !D)
42 return true;
43 bool isDeviceSideDecl = D->hasAttr<CUDADeviceAttr>() ||
44 D->hasAttr<CUDASharedAttr>() ||
45 D->hasAttr<CUDAGlobalAttr>();
46 return isDeviceSideDecl == LangOpts.CUDAIsDevice;
47}
48
49/// Return a DLL attribute from the declaration.
51 assert(!(D->hasAttr<DLLImportAttr>() && D->hasAttr<DLLExportAttr>()) &&
52 "A declaration cannot be both dllimport and dllexport.");
53 if (auto *Import = D->getAttr<DLLImportAttr>())
54 return Import;
55 if (auto *Export = D->getAttr<DLLExportAttr>())
56 return Export;
57 return nullptr;
58}
59
60/// Retrieve the depth and index of a template parameter.
61inline std::pair<unsigned, unsigned> getDepthAndIndex(const NamedDecl *ND) {
62 if (const auto *TTP = dyn_cast<TemplateTypeParmDecl>(ND))
63 return std::make_pair(TTP->getDepth(), TTP->getIndex());
64
65 if (const auto *NTTP = dyn_cast<NonTypeTemplateParmDecl>(ND))
66 return std::make_pair(NTTP->getDepth(), NTTP->getIndex());
67
68 const auto *TTP = cast<TemplateTemplateParmDecl>(ND);
69 return std::make_pair(TTP->getDepth(), TTP->getIndex());
70}
71
72/// Retrieve the depth and index of an unexpanded parameter pack.
73inline std::pair<unsigned, unsigned>
75 if (const auto *TTP = UPP.first.dyn_cast<const TemplateTypeParmType *>())
76 return std::make_pair(TTP->getDepth(), TTP->getIndex());
77
78 return getDepthAndIndex(cast<NamedDecl *>(UPP.first));
79}
80