CppParser
Loading...
Searching...
No Matches
cpptypetree.h
Go to the documentation of this file.
1/*
2 The MIT License (MIT)
3
4 Copyright (c) 2018 Satya Das
5
6 Permission is hereby granted, free of charge, to any person obtaining a copy of
7 this software and associated documentation files (the "Software"), to deal in
8 the Software without restriction, including without limitation the rights to
9 use, 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,
11 subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in all
14 copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, 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
20 IN 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
28#include <map>
29#include <set>
30
31struct CppTypeTreeNode;
41using CppTypeTree = std::map<std::string, CppTypeTreeNode>;
42
44{
45 bool operator()(const CppObj* lhs, const CppObj* rhs) const
46 {
47 if (lhs->objType_ < rhs->objType_)
48 return true;
49 if (lhs->objType_ > rhs->objType_)
50 return false;
51 return lhs < rhs;
52 }
53};
54
55using CppObjSet = std::set<const CppObj*, CppObjSetCmp>;
60{
69
71 : parent(nullptr)
72 {
73 }
74
75 bool has(const CppObj* cppObj) const
76 {
77 if (cppObjSet.count(cppObj))
78 return true;
79 for (const auto child : children)
80 {
81 if (child.second.has(cppObj))
82 return true;
83 }
84 return false;
85 }
86
88 {
89 for (const auto obj : cppObjSet)
90 {
91 if (obj->objType_ == objType)
92 return obj;
93 }
94
95 return nullptr;
96 }
97};
CppObjType objType(CppObj *cppObj)
Definition: cppast.cpp:189
CppObjType
Definition: cppconst.h:36
std::set< const CppObj *, CppObjSetCmp > CppObjSet
Definition: cpptypetree.h:55
std::map< std::string, CppTypeTreeNode > CppTypeTree
Represents the tree of types in a C++ program.
Definition: cpptypetree.h:41
bool operator()(const CppObj *lhs, const CppObj *rhs) const
Definition: cpptypetree.h:45
An abstract class that is used as base class of all other classes.
Definition: cppast.h:134
CppObjType objType_
Definition: cppast.h:135
A node in a CppTypeTree.
Definition: cpptypetree.h:60
CppObjSet cppObjSet
This needs to be a set because same namespace can be defined multiple times.
Definition: cpptypetree.h:66
CppTypeTree children
Definition: cpptypetree.h:67
const CppObj * getObjInSet(CppObjType objType) const
Definition: cpptypetree.h:87
CppTypeTreeNode * parent
Definition: cpptypetree.h:68
bool has(const CppObj *cppObj) const
Definition: cpptypetree.h:75