clang
22.0.0git
include
clang
AST
DeclGroup.h
Go to the documentation of this file.
1
//===- DeclGroup.h - Classes for representing groups of Decls ---*- 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 defines the DeclGroup, DeclGroupRef, and OwningDeclGroup classes.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_CLANG_AST_DECLGROUP_H
14
#define LLVM_CLANG_AST_DECLGROUP_H
15
16
#include "llvm/Support/TrailingObjects.h"
17
#include <cassert>
18
#include <cstdint>
19
20
namespace
clang
{
21
22
class
ASTContext
;
23
class
Decl
;
24
25
class
DeclGroup final :
private
llvm::TrailingObjects<DeclGroup, Decl *> {
26
// FIXME: Include a TypeSpecifier object.
27
unsigned
NumDecls = 0;
28
29
private
:
30
DeclGroup() =
default
;
31
DeclGroup(
unsigned
numdecls,
Decl
** decls);
32
33
public
:
34
friend
TrailingObjects
;
35
36
static
DeclGroup *
Create
(
ASTContext
&
C
,
Decl
**Decls,
unsigned
NumDecls);
37
38
unsigned
size
()
const
{
return
NumDecls; }
39
40
Decl
*&
operator[]
(
unsigned
i) {
return
getTrailingObjects(NumDecls)[i]; }
41
42
Decl
*
const
&
operator[]
(
unsigned
i)
const
{
43
return
getTrailingObjects(NumDecls)[i];
44
}
45
};
46
47
class
DeclGroupRef
{
48
// Note this is not a PointerIntPair because we need the address of the
49
// non-group case to be valid as a Decl** for iteration.
50
enum
Kind { SingleDeclKind=0x0, DeclGroupKind=0x1, Mask=0x1 };
51
52
Decl
* D =
nullptr
;
53
54
Kind getKind()
const
{
55
return
(Kind) (
reinterpret_cast<
uintptr_t
>
(D) & Mask);
56
}
57
58
public
:
59
DeclGroupRef
() =
default
;
60
explicit
DeclGroupRef
(
Decl
* d) : D(d) {}
61
explicit
DeclGroupRef
(
DeclGroup
* dg)
62
: D((
Decl
*) (reinterpret_cast<
uintptr_t
>(dg) | DeclGroupKind)) {}
63
64
static
DeclGroupRef
Create
(
ASTContext
&
C
,
Decl
**Decls,
unsigned
NumDecls) {
65
if
(NumDecls == 0)
66
return
DeclGroupRef
();
67
if
(NumDecls == 1)
68
return
DeclGroupRef
(Decls[0]);
69
return
DeclGroupRef
(
DeclGroup::Create
(
C
, Decls, NumDecls));
70
}
71
72
using
iterator
=
Decl
**;
73
using
const_iterator
=
Decl
*
const
*;
74
75
bool
isNull
()
const
{
return
D ==
nullptr
; }
76
bool
isSingleDecl
()
const
{
return
getKind() == SingleDeclKind; }
77
bool
isDeclGroup
()
const
{
return
getKind() == DeclGroupKind; }
78
79
Decl
*
getSingleDecl
() {
80
assert(
isSingleDecl
() &&
"Isn't a single decl"
);
81
return
D;
82
}
83
const
Decl
*
getSingleDecl
()
const
{
84
return
const_cast<
DeclGroupRef
*
>
(
this
)->
getSingleDecl
();
85
}
86
87
DeclGroup
&
getDeclGroup
() {
88
assert(
isDeclGroup
() &&
"Isn't a declgroup"
);
89
return
*((
DeclGroup
*)(
reinterpret_cast<
uintptr_t
>
(D) & ~Mask));
90
}
91
const
DeclGroup
&
getDeclGroup
()
const
{
92
return
const_cast<
DeclGroupRef
*
>
(
this
)->
getDeclGroup
();
93
}
94
95
iterator
begin
() {
96
if
(
isSingleDecl
())
97
return
D ? &D :
nullptr
;
98
return
&
getDeclGroup
()[0];
99
}
100
101
iterator
end
() {
102
if
(
isSingleDecl
())
103
return
D ? &D+1 :
nullptr
;
104
DeclGroup
&G =
getDeclGroup
();
105
return
&G[0] + G.
size
();
106
}
107
108
const_iterator
begin
()
const
{
109
if
(
isSingleDecl
())
110
return
D ? &D :
nullptr
;
111
return
&
getDeclGroup
()[0];
112
}
113
114
const_iterator
end
()
const
{
115
if
(
isSingleDecl
())
116
return
D ? &D+1 :
nullptr
;
117
const
DeclGroup
&G =
getDeclGroup
();
118
return
&G[0] + G.
size
();
119
}
120
121
void
*
getAsOpaquePtr
()
const
{
return
D; }
122
static
DeclGroupRef
getFromOpaquePtr
(
void
*Ptr) {
123
DeclGroupRef
X
;
124
X
.D =
static_cast<
Decl
*
>
(Ptr);
125
return
X
;
126
}
127
};
128
129
}
// namespace clang
130
131
namespace
llvm
{
132
133
// DeclGroupRef is "like a pointer", implement PointerLikeTypeTraits.
134
template
<
typename
T>
135
struct
PointerLikeTypeTraits
;
136
template
<>
137
struct
PointerLikeTypeTraits
<
clang
::DeclGroupRef> {
138
static
inline
void
*
getAsVoidPointer
(
clang::DeclGroupRef
P) {
139
return
P.
getAsOpaquePtr
();
140
}
141
142
static
inline
clang::DeclGroupRef
getFromVoidPointer
(
void
*P) {
143
return
clang::DeclGroupRef::getFromOpaquePtr
(P);
144
}
145
146
static
constexpr
int
NumLowBitsAvailable
= 0;
147
};
148
149
}
// namespace llvm
150
151
#endif
// LLVM_CLANG_AST_DECLGROUP_H
X
#define X(type, name)
Definition
Value.h:97
clang::ASTContext
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition
ASTContext.h:188
clang::DeclGroupRef
Definition
DeclGroup.h:47
clang::DeclGroupRef::isDeclGroup
bool isDeclGroup() const
Definition
DeclGroup.h:77
clang::DeclGroupRef::getFromOpaquePtr
static DeclGroupRef getFromOpaquePtr(void *Ptr)
Definition
DeclGroup.h:122
clang::DeclGroupRef::DeclGroupRef
DeclGroupRef(DeclGroup *dg)
Definition
DeclGroup.h:61
clang::DeclGroupRef::getSingleDecl
const Decl * getSingleDecl() const
Definition
DeclGroup.h:83
clang::DeclGroupRef::const_iterator
Decl *const * const_iterator
Definition
DeclGroup.h:73
clang::DeclGroupRef::getDeclGroup
const DeclGroup & getDeclGroup() const
Definition
DeclGroup.h:91
clang::DeclGroupRef::Create
static DeclGroupRef Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition
DeclGroup.h:64
clang::DeclGroupRef::end
const_iterator end() const
Definition
DeclGroup.h:114
clang::DeclGroupRef::begin
const_iterator begin() const
Definition
DeclGroup.h:108
clang::DeclGroupRef::begin
iterator begin()
Definition
DeclGroup.h:95
clang::DeclGroupRef::end
iterator end()
Definition
DeclGroup.h:101
clang::DeclGroupRef::DeclGroupRef
DeclGroupRef()=default
clang::DeclGroupRef::DeclGroupRef
DeclGroupRef(Decl *d)
Definition
DeclGroup.h:60
clang::DeclGroupRef::getDeclGroup
DeclGroup & getDeclGroup()
Definition
DeclGroup.h:87
clang::DeclGroupRef::getSingleDecl
Decl * getSingleDecl()
Definition
DeclGroup.h:79
clang::DeclGroupRef::iterator
Decl ** iterator
Definition
DeclGroup.h:72
clang::DeclGroupRef::getAsOpaquePtr
void * getAsOpaquePtr() const
Definition
DeclGroup.h:121
clang::DeclGroupRef::isSingleDecl
bool isSingleDecl() const
Definition
DeclGroup.h:76
clang::DeclGroupRef::isNull
bool isNull() const
Definition
DeclGroup.h:75
clang::DeclGroup
Definition
DeclGroup.h:25
clang::DeclGroup::size
unsigned size() const
Definition
DeclGroup.h:38
clang::DeclGroup::TrailingObjects
friend TrailingObjects
Definition
DeclGroup.h:34
clang::DeclGroup::Create
static DeclGroup * Create(ASTContext &C, Decl **Decls, unsigned NumDecls)
Definition
DeclGroup.cpp:20
clang::DeclGroup::operator[]
Decl *const & operator[](unsigned i) const
Definition
DeclGroup.h:42
clang::DeclGroup::operator[]
Decl *& operator[](unsigned i)
Definition
DeclGroup.h:40
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition
DeclBase.h:86
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition
CalledOnceCheck.h:17
clang::LinkageSpecLanguageIDs::C
@ C
Definition
DeclCXX.h:3001
clang::OpenACCClauseKind::Create
@ Create
'create' clause, allowed on Compute and Combined constructs, plus 'data', 'enter data',...
Definition
OpenACCKinds.h:245
llvm
Diagnostic wrappers for TextAPI types for error reporting.
Definition
Dominators.h:30
uintptr_t
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
Definition
opencl-c-base.h:166
llvm::PointerLikeTypeTraits< clang::DeclGroupRef >::getFromVoidPointer
static clang::DeclGroupRef getFromVoidPointer(void *P)
Definition
DeclGroup.h:142
llvm::PointerLikeTypeTraits< clang::DeclGroupRef >::getAsVoidPointer
static void * getAsVoidPointer(clang::DeclGroupRef P)
Definition
DeclGroup.h:138
llvm::PointerLikeTypeTraits< clang::DeclGroupRef >::NumLowBitsAvailable
static constexpr int NumLowBitsAvailable
Definition
DeclGroup.h:146
llvm::PointerLikeTypeTraits
Definition
DeclGroup.h:135
Generated on
for clang by
1.14.0