CppParser
Loading...
Searching...
No Matches
cppobj-info-accessor.h
Go to the documentation of this file.
1/*
2The MIT License (MIT)
3
4Copyright (c) 2018 Satya Das
5
6Permission is hereby granted, free of charge, to any person obtaining a copy of
7this software and associated documentation files (the "Software"), to deal in
8the Software without restriction, including without limitation the rights to
9use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10 the Software, and to permit persons to whom the Software is furnished to do so,
11subject to the following conditions:
12
13The above copyright notice and this permission notice shall be included in all
14copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#pragma once
25
26#include "cppast.h"
27#include "cppconst.h"
28#include "cpputil.h"
29
31{
33 return cppObj->accessType_;
34return (cppObj->owner() == nullptr) ? CppAccessType::kPublic : defaultAccessType(cppObj->owner()->compoundType());
35}
36
38{
39return accessType(cppObj.get());
40}
41
42inline bool isFunction(CppObj* cppObj)
43{
44return cppObj->objType_ == CppObjType::kFunction;
45}
46
47inline bool isFunction(CppObjPtr& cppObj)
48{
49return isFunction(cppObj.get());
50}
51
52inline bool isFunctionPtr(CppObj* cppObj)
53{
54return cppObj->objType_ == CppObjType::kFunctionPtr;
55}
56
57inline bool isFunctionPtr(CppObjPtr& cppObj)
58{
59return isFunctionPtr(cppObj.get());
60}
61
62inline bool isFunctionLike(CppObj* cppObj)
63{
66}
67
68inline bool isFunctionLike(CppObjPtr& cppObj)
69{
70return isFunctionLike(cppObj.get());
71}
72
73inline bool isDestructor(CppObj* cppObj)
74{
75return cppObj->objType_ == CppObjType::kDestructor;
76}
77
78inline bool isDestructor(CppObjPtr& cppObj)
79{
80return isDestructor(cppObj.get());
81}
82
83inline bool isEnum(CppObj* cppObj)
84{
85return cppObj->objType_ == CppObjType::kEnum;
86}
87
88inline bool isEnum(CppObjPtr cppObj)
89{
90return isEnum(cppObj.get());
91}
92
93inline bool isTypedefName(CppObj* cppObj)
94{
95return cppObj->objType_ == CppObjType::kTypedefName;
96}
97
98inline bool isTypedefName(CppObjPtr& cppObj)
99{
100return isTypedefName(cppObj.get());
101}
102
103inline bool isUsingDecl(CppObj* cppObj)
104{
105return cppObj->objType_ == CppObjType::kUsingDecl;
106}
107
108inline bool isUsingDecl(CppObjPtr& cppObj)
109{
110return isUsingDecl(cppObj.get());
111}
112
113inline bool isCompound(CppObj* cppObj)
114{
115return cppObj->objType_ == CppObjType::kCompound;
116}
117
118inline bool isCompound(CppObjPtr& cppObj)
119{
120return isCompound(cppObj.get());
121}
122
123inline bool isFwdClsDecl(CppObj* cppObj)
124{
125return cppObj->objType_ == CppObjType::kFwdClsDecl;
126}
127
128inline bool isFwdClsDecl(CppObjPtr& cppObj)
129{
130return isFwdClsDecl(cppObj.get());
131}
132
133inline bool isNamespaceLike(CppObj* cppObj)
134{
135if (!isCompound(cppObj))
136 return false;
137auto* compound = static_cast<CppCompound*>(cppObj);
138return compound->compoundType() & CppCompoundType::kNamespace;
139}
140
141inline bool isNamespaceLike(CppObjPtr& cppObj)
142{
143return isNamespaceLike(cppObj.get());
144}
145
146inline bool isClassLike(CppObj* cppObj)
147{
148if (!isCompound(cppObj))
149 return false;
150auto* compound = static_cast<CppCompound*>(cppObj);
151return (compound->compoundType() & CppCompoundType::kClass) == CppCompoundType::kClass;
152}
153
154inline bool isClassLike(CppObjPtr& cppObj)
155{
156return isClassLike(cppObj.get());
157}
158
159inline bool isTypedefLike(CppObj* cppObj)
160{
161return (cppObj->objType_ == CppObjType::kTypedefName) || (cppObj->objType_ == CppObjType::kUsingDecl);
162}
163
164inline bool isTypedefLike(CppObjPtr& cppObj)
165{
166return isTypedefLike(cppObj.get());
167}
168
169inline bool isPreProcessorType(CppObj* cppObj)
170{
173}
174
175inline bool isPreProcessorType(CppObjPtr& cppObj)
176{
177return isPreProcessorType(cppObj.get());
178}
179
180inline bool isVar(CppObj* cppObj)
181{
182return cppObj->objType_ == CppObjType::kVar;
183}
184
185inline bool isVar(CppObjPtr& cppObj)
186{
187return isVar(cppObj.get());
188}
189
190inline bool isVarList(CppObj* cppObj)
191{
192return cppObj->objType_ == CppObjType::kVarList;
193}
194
195inline bool isVarList(CppObjPtr& cppObj)
196{
197return isVarList(cppObj.get());
198}
199
200inline bool isExpr(CppObj* cppObj)
201{
202return cppObj->objType_ == CppObjType::kExpression;
203}
204
205inline bool isExpr(CppObjPtr& cppObj)
206{
207return isExpr(cppObj.get());
208}
209
210inline bool isPublic(CppObj* cppObj)
211{
212return accessType(cppObj) == CppAccessType::kPublic;
213}
214
215inline bool isPublic(CppObjPtr& cppObj)
216{
217return isPublic(cppObj.get());
218}
219
220inline bool isProtected(CppObj* cppObj)
221{
222return accessType(cppObj) == CppAccessType::kProtected;
223}
224
225inline bool isProtected(CppObjPtr& cppObj)
226{
227return accessType(cppObj) == CppAccessType::kProtected;
228}
229
230inline bool isPrivate(CppObj* cppObj)
231{
232return accessType(cppObj) == CppAccessType::kPrivate;
233}
234
235inline bool isPrivate(CppObjPtr& cppObj)
236{
237return isPrivate(cppObj.get());
238}
239
240inline CppCompound* root(CppObj* cppObj)
241{
242if (cppObj->owner() == nullptr)
243 return isCompound(cppObj) ? const_cast<CppCompound*>(static_cast<CppCompound*>(cppObj)) : nullptr;
244if (cppObj->owner()->owner() == nullptr)
245 return cppObj->owner();
246return root(cppObj->owner());
247}
248
249inline CppCompound* root(CppObjPtr& cppObj)
250{
251return root(cppObj.get());
252}
CppAccessType
Definition: cppconst.h:103
@ kCPreProcessorTypeEnds
@ kCPreProcessorTypeStarts
@ kNamespace
Definition: cppconst.h:94
@ kClass
Definition: cppconst.h:95
bool isFunctionLike(CppObj *cppObj)
CppCompound * root(CppObj *cppObj)
bool isClassLike(CppObj *cppObj)
bool isPrivate(CppObj *cppObj)
bool isVarList(CppObj *cppObj)
bool isFunction(CppObj *cppObj)
bool isExpr(CppObj *cppObj)
bool isFwdClsDecl(CppObj *cppObj)
bool isEnum(CppObj *cppObj)
bool isPublic(CppObj *cppObj)
bool isTypedefLike(CppObj *cppObj)
CppAccessType accessType(CppObj *cppObj)
bool isPreProcessorType(CppObj *cppObj)
bool isUsingDecl(CppObj *cppObj)
bool isProtected(CppObj *cppObj)
bool isCompound(CppObj *cppObj)
bool isTypedefName(CppObj *cppObj)
bool isVar(CppObj *cppObj)
bool isFunctionPtr(CppObj *cppObj)
bool isDestructor(CppObj *cppObj)
bool isNamespaceLike(CppObj *cppObj)
std::unique_ptr< CppObj > CppObjPtr
Definition: cpptoken.h:109
CppAccessType defaultAccessType(CppCompoundType type)
Definition: cpputil.h:45
All classes, structs, unions, and namespaces can be classified as a Compound object.
Definition: cppast.h:927
CppCompoundType compoundType()
Definition: cppast.h:969
An abstract class that is used as base class of all other classes.
Definition: cppast.h:134
CppCompound * owner()
Definition: cppast.h:145
CppAccessType accessType_
All objects do not need this.
Definition: cppast.h:136
CppObjType objType_
Definition: cppast.h:135