CppParser
Loading...
Searching...
No Matches
cppast.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
11furnished to do so, subject 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
19SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21SOFTWARE.
22 */
23
24#pragma once
25
36/*
37x : not used anywhere.
38* : only used off AST header.
39##: used in AST header.
40--: reviewed for nullptr handling
41
42##CppExprPtr --
43##AttribSpecifier --
44##AttribSpecifierSequence --
45##CppCompoundPtr --
46##CppObjPtr --
47##CppVarTypePtr --
48##CppTemplateParamListPtr --
49##CppVarPtr --
50##CppVarListPtr --
51##CppInheritanceListPtr --
52##CppCompoundPtr --
53##CppFuncThrowSpecPtr --
54##CppParamVectorPtr --
55##CppVarTypePtr --
56##CppEnumItemListPtr --
57##CppSwitchBodyPtr --
58##CppCatchBlockPtr --
59##CppCatchBlocks --
60
61
62*CppIncludeEPtr
63*CppVarTypeEPtr
64*CppConstVarTypeEPtr
65*CppVarEPtr
66*CppConstVarEPtr
67*CppVarListEPtr
68*CppCompoundEPtr
69*CppConstCompoundEPtr
70*CppVarTypeEPtr
71*CppFunctionEPtr
72*CppConstFunctionEPtr
73*CppExprEPtr
74*CppConstExprEPtr
75*CppLabelEPtr
76
77
78xCppDefineEPtr
79xCppUndefEPtr
80xCppHashIfEPtr
81xCppPragmaEPtr
82xCppHashErrorEPtr
83xCppHashWarningEPtr
84xCppUnRecogPreProEPtr
85xCppTypedefNameEPtr
86xCppTypedefListEPtr
87xCppMacroCallEPtr
88xCppFwdClsDeclEPtr
89xCppFunctionPointerEPtr
90xCppConstructorEPtr
91xCppDestructorEPtr
92xCppTypeConverterEPtr
93xCppUsingNamespaceDeclEPtr
94xCppUsingDeclEPtr
95xCppConstUsingDeclEPtr
96xCppNamespaceAliasEPtr
97xCppDocCommentEPtr
98xCppEnumEPtr
99xCppIfBlockEPtr
100xCppWhileBlockEPtr
101xCppDoWhileBlockEPtr
102xCppForBlockEPtr
103xCppSwitchBlockEPtr
104
105*/
106
107#include "cppconst.h"
108#include "cppeasyptr.h"
109#include "cppvisitorbase.h"
110#include "typemodifier.h"
111
112#include "string-utils.h"
113
114#include <cassert>
115#include <cstdint>
116#include <iostream>
117#include <list>
118#include <memory>
119#include <string>
120#include <utility>
121#include <vector>
122
124#define VISIT_COND(CALL) \
125 if (!CALL) \
126 return;
127
128struct CppCompound;
129
133struct CppObj
134{
137
139 : objType_(type)
141 , owner_(nullptr)
142 {
143 }
144
146 {
147 return owner_;
148 }
150 {
151 //assert(owner_ == nullptr); ///TODO: Mem leak
152 owner_ = o;
153 }
154
155 virtual void accept(CppVisitorBase* v) = 0;
156
157 virtual ~CppObj() { }
158
159private:
161};
162
166struct CppBlob : public CppObj
167{
168 static constexpr CppObjType kObjectType = CppObjType::kBlob;
169 std::string blob_;
170
171 CppBlob(std::string blob)
173 , blob_(std::move(trimBlob(blob)))
174 {
175 }
176
177 void accept(CppVisitorBase* v) override { }
178};
179
180struct CppDefine : public CppObj
181{
182 static constexpr CppObjType kObjectType = CppObjType::kHashDefine;
183
185 {
191 };
193 std::string name_;
194 std::string defn_;
195
196 CppDefine(DefType defType, std::string name, std::string defn = std::string())
198 , defType_(defType)
199 , name_(std::move(name))
200 , defn_(std::move(defn))
201 {
202 }
203
204 void accept(CppVisitorBase* v) override
205 {
206 VISIT_COND(v->visit(this));
207 }
208};
209
211
212struct CppUndef : public CppObj
213{
214 static constexpr CppObjType kObjectType = CppObjType::kHashUndef;
215
216 std::string name_;
217
218 CppUndef(std::string name)
220 , name_(std::move(name))
221 {
222 }
223
224 void accept(CppVisitorBase* v) override
225 {
226 VISIT_COND(v->visit(this));
227 }
228};
229
231
232struct CppInclude : public CppObj
233{
234 static constexpr CppObjType kObjectType = CppObjType::kHashInclude;
235
236 std::string name_;
237
238 CppInclude(std::string name)
240 , name_(std::move(name))
241 {
242 }
243
244 void accept(CppVisitorBase* v) override
245 {
246 VISIT_COND(v->visit(this));
247 }
248};
249
250struct CppImport : public CppObj
251{
252 static constexpr CppObjType kObjectType = CppObjType::kHashImport;
253
254 std::string name_;
255
256 CppImport(std::string name)
258 , name_(std::move(name))
259 {
260 }
261
262 void accept(CppVisitorBase* v) override
263 {
264 VISIT_COND(v->visit(this));
265 }
266};
267
269
275struct CppHashIf : public CppObj
276{
277 static constexpr CppObjType kObjectType = CppObjType::kHashIf;
278
280 {
286 kEndIf
287 };
288
290 std::string cond_;
291
292 CppHashIf(CondType condType, std::string cond = std::string())
294 , condType_(condType)
295 , cond_(std::move(cond))
296 {
297 }
298
299 void accept(CppVisitorBase* v) override
300 {
301 VISIT_COND(v->visit(this));
302 }
303};
304
306
307struct CppPragma : public CppObj
308{
309 static constexpr CppObjType kObjectType = CppObjType::kHashPragma;
310
311 std::string defn_;
312
313 CppPragma(std::string defn)
315 , defn_(std::move(defn))
316 {
317 }
318
319 void accept(CppVisitorBase* v) override
320 {
321 VISIT_COND(v->visit(this));
322 }
323};
324
326
327struct CppHashError : public CppObj
328{
329 static constexpr CppObjType kObjectType = CppObjType::kHashError;
330
331 std::string err_;
332
333 CppHashError(std::string err)
335 , err_(std::move(err))
336 {
337 }
338
339 void accept(CppVisitorBase* v) override
340 {
341 VISIT_COND(v->visit(this));
342 }
343};
344
346
347struct CppHashWarning : public CppObj
348{
349 static constexpr CppObjType kObjectType = CppObjType::kHashWarning;
350
351 std::string err_;
352
353 CppHashWarning(std::string err)
355 , err_(std::move(err))
356 {
357 }
358
359 void accept(CppVisitorBase* v) override
360 {
361 VISIT_COND(v->visit(this));
362 }
363};
364
366
371{
372 static constexpr CppObjType kObjectType = CppObjType::kUnRecogPrePro;
373
374 std::string name_;
375 std::string defn_;
376
377 CppUnRecogPrePro(std::string name, std::string defn)
379 , name_(std::move(name))
380 , defn_(std::move(defn))
381 {
382 }
383
384 void accept(CppVisitorBase* v) override
385 {
386 VISIT_COND(v->visit(this));
387 }
388};
389
390struct CppExpr;
391using CppExprPtr = std::unique_ptr<CppExpr>;
393using AttribSpecifierArray = std::vector<AttribSpecifier>;
394using AttribSpecifierSequence = std::unique_ptr<AttribSpecifierArray>;
395
401{
403 {
405 }
407 {
408 attributeSpecifiers_ = AttribSpecifierSequence(attribSpecifierArray);
409 }
410
411private:
412 AttribSpecifierSequence attributeSpecifiers_; // C++11 Attribute specifier sequence
413};
414
416using CppCompoundPtr = std::unique_ptr<CppCompound>;
417using CppObjPtr = std::unique_ptr<CppObj>;
418
419struct CppFunctionPointer;
420struct CppEnum;
421
422struct CppVarType : public CppObj, public AttribSpecified
423{
424 static constexpr CppObjType kObjectType = CppObjType::kVarType;
425
426 bool paramPack_ {false};
427
428 CppVarType(std::string baseType, CppTypeModifier modifier = CppTypeModifier());
433 CppVarType(CppVarType& varType);
434
435 std::string& baseType()
436 {
437 return baseType_;
438 }
439 void baseType(std::string _baseType)
440 {
441 baseType_ = std::move(_baseType);
442 }
444 {
445 return compound_.get();
446 }
447 std::uint32_t typeAttr()
448 {
449 return typeAttr_;
450 }
451 void typeAttr(std::uint32_t attr)
452 {
453 typeAttr_ = attr;
454 }
455 void addAttr(std::uint32_t attr)
456 {
457 if ((attr & CppIdentifierAttrib::kConst) == 0)
458 typeAttr_ |= attr;
459 else
461 }
462
464 {
465 return typeModifier_;
466 }
467
468 void accept(CppVisitorBase* v) override
469 {
470 VISIT_COND(v->visit(this));
471 if (compound_ != nullptr)
472 compound_->accept(v);
473 }
474
475private:
479 , typeModifier_(modifier)
481 {
482 }
483
484private:
485 std::string baseType_; // This is the basic data type of var e.g. for ' int*& pi' base-type is int.
488 std::uint32_t typeAttr_ {0}; // Attribute associated with type, e.g. static, extern, extern "C", , volatile.
489};
490
492using CppArraySizes = std::vector<CppExprPtr>;
493
495{
496 CppVarDecl(std::string name)
497 : name_(std::move(name))
498 {
499 }
500
501 CppVarDecl(std::string name, CppExpr* assign, AssignType assignType = AssignType::kNone);
502
503 std::string& name()
504 {
505 return name_;
506 }
507 void name(std::string _name)
508 {
509 name_ = std::move(_name);
510 }
511
513 {
514 return assignValue_.get();
515 }
517 {
518 return assignType_;
519 }
521 {
522 assert(assignType_ == AssignType::kNone);
523 assignValue_.reset(assignVal);
525 }
526
528 {
529 return bitField_.get();
530 }
531 void bitField(CppExpr* _bitField)
532 {
533 bitField_.reset(_bitField);
534 }
535
537 {
538 return arraySizes_;
539 }
540 void addArraySize(CppExpr* arraySize)
541 {
542 arraySizes_.emplace_back(arraySize);
543 }
544
545private:
546 std::string name_;
547 CppExprPtr assignValue_; // Value assigned at declaration.
548 AssignType assignType_ {AssignType::kNone};
551};
552
553using CppVarTypePtr = std::unique_ptr<CppVarType>;
554
555struct CppTemplateParam;
556using CppTemplateParamList = std::vector<std::unique_ptr<CppTemplateParam>>;
557using CppTemplateParamListPtr = std::unique_ptr<CppTemplateParamList>;
558
564struct CppVar : public CppObj
565{
566 static constexpr CppObjType kObjectType = CppObjType::kVar;
567
571 , varDecl_(std::move(varDecl))
572 {
573 }
574
577 , varType_(std::move(varType))
578 , varDecl_(std::move(varDecl))
579 {
580 }
581
584 , varType_(new CppVarType(accessType, fptr, modifier))
585 , varDecl_(std::string())
586 {
587 }
588
590 {
591 return varType_.get();
592 }
593 void varType(CppVarTypePtr _varType)
594 {
595 varType_ = std::move(_varType);
596 }
597
598 std::string& name()
599 {
600 return varDecl_.name();
601 }
602
603 std::uint32_t typeAttr()
604 {
605 return varType_->typeAttr();
606 }
607 void addAttr(std::uint32_t attr)
608 {
609 varType_->addAttr(attr);
610 }
611
613 {
614 return varDecl_;
615 }
616
618 {
619 return varDecl_.assignValue();
620 }
622 {
623 return varDecl_.assignType();
624 }
626 {
627 varDecl_.assign(assignVal, assignType);
628 }
629
631 {
632 return varDecl_.bitField();
633 }
634 void bitField(CppExpr* _bitField)
635 {
636 varDecl_.bitField(_bitField);
637 }
638
640 {
641 return varDecl_.arraySizes();
642 }
643 void addArraySize(CppExpr* arraySize)
644 {
645 varDecl_.addArraySize(arraySize);
646 }
647
648 std::string& apidecor()
649 {
650 return apidecor_;
651 }
652 void apidecor(std::string _apidecor)
653 {
654 apidecor_ = std::move(_apidecor);
655 }
656
658 {
659 return templSpec_.get();
660 }
662 {
663 templSpec_.reset(templParamList);
664 }
665
666 void accept(CppVisitorBase* v) override
667 {
668 VISIT_COND(v->visit(this));
669 if (varType_ != nullptr)
670 VISIT_COND(v->visit(varType_.get()));
671 // `CppVarDecl` is not an AST node, it is a member of `CppVar`.
672 }
673
674private:
677 std::string apidecor_; // It holds things like WINAPI, __declspec(dllexport), etc.
679};
680
681using CppVarPtr = std::unique_ptr<CppVar>;
683
685{
687 : CppTypeModifier(modifier)
688 , CppVarDecl(std::move(varDecl))
689 {
690 }
691};
692
693using CppVarDeclList = std::vector<CppVarDeclInList>;
694
698struct CppVarList : public CppObj
699{
700 static constexpr CppObjType kObjectType = CppObjType::kVarList;
701
703
707 {
708 addVarDecl(std::move(varDecl));
709 }
711 {
712 varDeclList_.push_back(std::move(varDecl));
713 }
715 {
716 return firstVar_;
717 }
719 {
720 return varDeclList_;
721 }
722
723 void accept(CppVisitorBase* v) override
724 {
725 VISIT_COND(v->visit(this));
726 if (firstVar_ != nullptr)
727 VISIT_COND(v->visit(firstVar_.get()));
728 // `CppVarDeclList` is not an AST node, it is a member of `CppVarList`
729 }
730
731private:
733};
734
735struct CppTypedefName : public CppObj
736{
737 static constexpr CppObjType kObjectType = CppObjType::kTypedefName;
738
740
743 , var_(var)
744 {
745 }
746
747 void accept(CppVisitorBase* v) override
748 {
749 VISIT_COND(v->visit(this));
750 if (var_ != nullptr)
751 VISIT_COND(v->visit(var_.get()));
752 }
753};
754
756
757using CppVarListPtr = std::unique_ptr<CppVarList>;
759
760struct CppTypedefList : public CppObj
761{
762 static constexpr CppObjType kObjectType = CppObjType::kTypedefNameList;
763
765
767 : CppObj(kObjectType, varList->accessType_)
768 , varList_(varList)
769 {
770 }
771
772 void accept(CppVisitorBase* v) override
773 {
774 VISIT_COND(v->visit(this));
775 if (varList_ != nullptr)
776 VISIT_COND(v->visit(varList_.get()));
777 }
778};
779
781
783{
784 static constexpr CppObjType kObjectType = CppObjType::kMacroCall;
785
786 std::string macroCall_;
787
788 CppMacroCall(std::string macroCall, CppAccessType accessType)
790 , macroCall_(std::move(macroCall))
791 {
792 }
793
794 void accept(CppVisitorBase* v) override
795 {
796 VISIT_COND(v->visit(this));
797 }
798};
799
801
803
805{
806 std::string baseName;
808 bool isVirtual {false};
809
810 CppInheritInfo(std::string _baseName, CppAccessType _inhType, bool virtualInheritance = false)
811 : baseName(std::move(_baseName))
812 , inhType(_inhType)
813 , isVirtual(virtualInheritance)
814 {
815 }
816};
817
818struct CppFunctionPointer;
823{
824 // If not nullptr then template param is not of type typename/class
825 std::unique_ptr<CppObj> paramType_;
826 std::string paramName_;
827
828 CppTemplateParam(std::string paramName)
829 : paramType_(nullptr)
830 , paramName_(std::move(paramName))
831 {
832 }
833
834 CppTemplateParam(CppVarType* paramType, std::string paramName)
835 : paramType_(paramType)
836 , paramName_(std::move(paramName))
837 {
838 }
839
840 CppTemplateParam(CppFunctionPointer* paramType, std::string paramName);
841
843 {
844 return defaultArg_.get();
845 }
846
847 void defaultArg(CppObj* defParam)
848 {
849 assert(!defaultArg_);
850 defaultArg_.reset(defParam);
851 }
852
853private:
854 CppObjPtr defaultArg_; //< Can be CppVarType or CppExpr
855};
856
857struct CppFwdClsDecl : public CppObj
858{
859 static constexpr CppObjType kObjectType = CppObjType::kFwdClsDecl;
860
862 std::string name_;
863 std::string apidecor_;
864
866 std::string name,
867 std::string apidecor,
868 CppCompoundType cmpType = CppCompoundType::kNoCompound)
870 , cmpType_(cmpType)
871 , name_(std::move(name))
872 , apidecor_(std::move(apidecor))
873 , attr_(0)
874 {
875 }
876
877 CppFwdClsDecl(CppAccessType accessType, std::string name, CppCompoundType cmpType = CppCompoundType::kNoCompound)
878 : CppFwdClsDecl(accessType, name, std::string(), cmpType)
879 {
880 }
881
882 std::uint32_t attr()
883 {
884 return attr_;
885 }
886 void addAttr(std::uint32_t _attr)
887 {
888 attr_ |= _attr;
889 }
890
892 {
893 return templSpec_.get();
894 }
896 {
897 templSpec_.reset(templParamList);
898 }
899
900 void accept(CppVisitorBase* v) override
901 {
902 VISIT_COND(v->visit(this));
903 }
904
905private:
907 std::uint32_t attr_ {0};
908};
909
911
912using CppInheritanceList = std::list<CppInheritInfo>;
913using CppInheritanceListPtr = std::unique_ptr<CppInheritanceList>;
914using CppObjPtrArray = std::vector<std::unique_ptr<CppObj>>;
915
916struct CppConstructor;
917struct CppDestructor;
918
926struct CppCompound : public CppObj, public AttribSpecified
927{
928 static constexpr CppObjType kObjectType = CppObjType::kCompound;
929
932 , name_(std::move(name))
933 , compoundType_(type)
934 , inheritanceList_(nullptr)
935 {
936 }
937
938 CppCompound(CppAccessType accessType, CppCompoundType type = CppCompoundType::kUnknownCompound)
939 : CppCompound(std::string(), accessType, type)
940 {
941 }
942
945 {
946 }
947
949 : CppCompound(std::string(), type)
950 {
951 }
952
953 std::string& name()
954 {
955 return name_;
956 }
957 void name(std::string _name)
958 {
959 name_ = std::move(_name);
960 }
961 std::string justName()
962 {
963 auto itr = name_.rfind(':');
964 if (itr == name_.npos)
965 return name();
966 return name().substr(itr + 1);
967 }
968
970 {
971 return compoundType_;
972 }
974 {
975 // Change of compound type is largely not allowed.
976 // Although while parsing 'extern "C"' the inner part may be first parsed as block
977 // which gets promoted as extern-c-block.
978 assert((compoundType_ == CppCompoundType::kUnknownCompound) || (compoundType_ == CppCompoundType::kBlock));
980 }
981
983 {
984 return members_;
985 }
986
987 std::string& apidecor()
988 {
989 return apidecor_;
990 }
991 void apidecor(std::string apidecor)
992 {
993 apidecor_ = std::move(apidecor);
994 }
995
997 {
998 return templSpec_.get();
999 }
1001 {
1002 templSpec_ = std::move(_templateParamList);
1003 }
1004 void templateParamList(CppTemplateParamList* _templateParamList)
1005 {
1006 templSpec_.reset(_templateParamList);
1007 }
1008
1010 {
1011 return inheritanceList_;
1012 }
1014 {
1015 inheritanceList_ = std::move(_inheritanceList);
1016 }
1017 void inheritanceList(CppInheritanceList* _inheritanceList)
1018 {
1019 inheritanceList_.reset(_inheritanceList);
1020 }
1021
1023 {
1024 mem->owner(this);
1025 members_.emplace_back(mem);
1027 }
1029 {
1030 mem->owner(this);
1031 members_.push_back(std::move(mem));
1032 assignSpecialMember(members_.back().get());
1033 }
1034 void addMemberAt(CppObjPtr &&mem, unsigned index)
1035 {
1036 assert(members_.begin() + index <= members_.end());
1037 mem->owner(this);
1038 members_.insert(members_.begin() + index, std::move(mem));
1039 assignSpecialMember(members_.back().get());
1040 }
1042 {
1043 mem->owner(this);
1044 members_.emplace(members_.begin(), mem);
1046 }
1048 {
1049 mem->owner(this);
1050 members_.insert(members_.begin(), std::move(mem));
1051 assignSpecialMember(members_.front().get());
1052 }
1053
1055 {
1056 assert(idx < members_.size());
1057 auto ret = std::move(members_[idx]);
1058 members_.erase(members_.begin() + idx);
1059
1060 return ret;
1061 }
1062
1063 void addBaseClass(std::string baseName, CppAccessType inheritType)
1064 {
1065 if (inheritanceList_ == nullptr)
1067 inheritanceList_->emplace_back(baseName, inheritType);
1068 }
1069
1071 bool hasPureVirtual();
1073 {
1074 return copyCtor_;
1075 }
1077 {
1078 return moveCtor_;
1079 }
1080 std::vector<CppConstructor*>& ctors()
1081 {
1082 return ctors_;
1083 }
1085 {
1086 return dtor_;
1087 }
1089
1090 void addAttr(std::uint32_t _attr)
1091 {
1092 attr_ |= _attr;
1093 }
1094
1095 bool hasAttr(std::uint32_t _attr)
1096 {
1097 return (attr_ & _attr) == _attr;
1098 }
1099
1101 {
1102 return (members_.size() == 1) && (members_.front()->objType_ == CppBlob::kObjectType);
1103 }
1104
1105 void accept(CppVisitorBase* v) override
1106 {
1107 VISIT_COND(v->visit(this));
1108 for (auto& c : ctors_)
1109 {
1110 VISIT_COND(v->visit(c));
1111 }
1112 if (copyCtor_ != nullptr)
1113 {
1115 }
1116 if (copyCtor_ != nullptr)
1117 {
1119 }
1120 if (copyCtor_ != nullptr)
1121 {
1122 VISIT_COND(v->visit(dtor_));
1123 }
1124 for (auto& m : members_)
1125 {
1126 m->accept(v);
1127 }
1128 }
1129
1130private:
1131 void assignSpecialMember(CppObj* mem);
1132
1133private:
1134 std::string name_;
1136 CppObjPtrArray members_; // Objects arranged in sequential order from top to bottom.
1138 std::string apidecor_;
1140 std::uint32_t attr_ {0}; // e.g. final
1141
1142 std::vector<CppConstructor*> ctors_;
1146
1147 mutable TriStateBool hasVirtual_ = TriStateBool::Unknown;
1148 mutable TriStateBool hasPureVirtual_ = TriStateBool::Unknown;
1149};
1150
1152
1153struct CppFunctionPointer;
1154
1155using CppIdentifierList = std::vector<std::string>;
1157using CppCompoundPtr = std::unique_ptr<CppCompound>;
1158using CppFuncThrowSpecPtr = std::unique_ptr<CppFuncThrowSpec>;
1159
1161{
1163 {
1164 return throwSpec_.get();
1165 }
1166 void throwSpec(CppFuncThrowSpec* _throwSpec)
1167 {
1168 throwSpec_.reset(_throwSpec);
1169 }
1170
1172 {
1173 return defn_.get();
1174 }
1175 void defn(CppCompound* _defn)
1176 {
1177 defn_.reset(_defn);
1178 }
1179
1180protected:
1182 : CppObj(type, accessType)
1183 {
1184 }
1185
1186private:
1187 CppCompoundPtr defn_; // If it is nullptr then this object is just for declaration.
1189};
1190
1195{
1196 std::string name_;
1197
1198 std::uint32_t attr()
1199 {
1200 return attr_;
1201 }
1202 void addAttr(std::uint32_t _attr)
1203 {
1204 attr_ |= _attr;
1205 }
1206 bool hasAttr(std::uint32_t _attr)
1207 {
1208 return ((attr_ & _attr) == _attr);
1209 }
1210
1211 std::string& decor1()
1212 {
1213 return decor1_;
1214 }
1215 void decor1(std::string _decor)
1216 {
1217 decor1_ = std::move(_decor);
1218 }
1219
1220 std::string& decor2()
1221 {
1222 return decor2_;
1223 }
1224 void decor2(std::string _decor)
1225 {
1226 decor2_ = std::move(_decor);
1227 }
1228
1230 {
1231 return templSpec_.get();
1232 }
1234 {
1235 templSpec_.reset(templParamList);
1236 }
1237
1238protected:
1239 CppFunctionBase(CppObjType type, CppAccessType accessType, std::string name, std::uint32_t attr)
1241 , name_(std::move(name))
1242 , attr_(attr)
1243 {
1244 }
1245
1246private:
1247 std::uint32_t attr_; // e.g.: , static, virtual, inline, constexpr, etc.
1248 std::string decor1_; // e.g. __declspec(dllexport)
1249 std::string decor2_; // e.g. __stdcall
1251};
1252
1253using CppParamVector = std::vector<CppObjPtr>;
1254using CppParamVectorPtr = std::unique_ptr<CppParamVector>;
1255
1257{
1259 {
1260 return params_ && !params_->empty();
1261 }
1262
1264 {
1265 return params_.get();
1266 }
1267
1268protected:
1271 std::string name,
1273 std::uint32_t attr)
1274 : CppFunctionBase(type, accessType, std::move(name), attr)
1275 , params_(params)
1276 {
1277 }
1278
1279protected:
1281};
1282
1283using CppVarTypePtr = std::unique_ptr<CppVarType>;
1285
1287{
1288 static constexpr CppObjType kObjectType = CppObjType::kFunction;
1289
1291
1293 std::string name,
1294 CppVarType* retType,
1296 std::uint32_t attr)
1298 , retType_(retType)
1299 {
1300 }
1301
1302 static unsigned findMainFunctionFromMembers(const CppObjPtrArray &members) {
1303 unsigned idx=0;
1304 for (auto &m: members) {
1305 auto ptr = m.get();
1306 if (ptr->objType_ == CppObjType::kFunction) {
1307 auto ptrFunc = static_cast<CppFunction*>(ptr);
1308 if(ptrFunc->name_ == "main") {
1309 break;
1310 }
1311 }
1312 idx++;
1313 }
1314 return idx;
1315 }
1316
1317 void accept(CppVisitorBase* v) override
1318 {
1319 VISIT_COND(v->visit(this));
1320 if (retType_ != nullptr)
1321 VISIT_COND(v->visit(retType_.get()));
1322 if (params_ != nullptr)
1323 {
1324 for (auto& p : *params_)
1325 {
1326 p->accept(v);
1327 }
1328 }
1329 defn()->accept(v);
1330 }
1331
1332protected:
1335 std::string name,
1336 CppVarType* retType,
1338 std::uint32_t attr)
1339 : CppFuncCtorBase(type, accessType, std::move(name), params, attr)
1340 , retType_(retType)
1341 {
1342 }
1343};
1344
1346{
1347 static constexpr CppObjType kObjectType = CppObjType::kLambda;
1348
1353
1354 CppLambda(CppExpr* captures, CppParamVector* params, CppCompound* defn, CppVarType* retType = nullptr)
1356 , captures_(captures)
1357 , params_(params)
1358 , retType_(retType)
1359 , defn_(defn)
1360 {
1361 }
1362
1363 void accept(CppVisitorBase* v) override
1364 {
1365 VISIT_COND(v->visit(this));
1366 if (captures_ != nullptr)
1367 VISIT_COND(v->visit(captures_.get()));
1368 if (params_ != nullptr)
1369 {
1370 for (auto& p : *params_)
1371 {
1372 p->accept(v);
1373 }
1374 }
1375 if (retType_ != nullptr)
1376 VISIT_COND(v->visit(retType_.get()));
1377 if (defn_ != nullptr)
1378 defn_->accept(v);
1379 }
1380};
1381
1383
1390{
1391 static constexpr CppObjType kObjectType = CppObjType::kFunctionPtr;
1392
1393 std::string ownerName_;
1394
1396 std::string name,
1397 CppVarType* retType,
1399 std::uint32_t attr,
1400 std::string ownerName = std::string())
1401 : CppFunction(kObjectType, accessType, std::move(name), retType, params, attr)
1402 , ownerName_(std::move(ownerName))
1403 {
1404 }
1405
1406 void accept(CppVisitorBase* v) override
1407 {
1408 VISIT_COND(v->visit(this));
1409 if (params_ != nullptr)
1410 {
1411 for (auto& p : *params_)
1412 {
1413 p->accept(v);
1414 }
1415 }
1416 VISIT_COND(v->visit(retType_.get()));
1417 }
1418};
1419
1421
1425using CppMemInit = std::pair<std::string, CppExpr*>;
1426
1431{
1433 union
1434 {
1435 std::list<CppMemInit>* memInitList;
1437 };
1438};
1439
1441{
1442 return CppMemInits {false, {nullptr}};
1443}
1444
1445inline CppMemInits makeCppMemInitList(std::list<CppMemInit>* memInitList)
1446{
1448 memInits.memInitList = memInitList;
1449
1450 return memInits;
1451}
1452
1454{
1456 memInits.memInitListIsABlob_ = true;
1457 memInits.blob = blob;
1458
1459 return memInits;
1460}
1461
1463{
1464 static constexpr CppObjType kObjectType = CppObjType::kConstructor;
1465
1467
1469 std::string name,
1471 CppMemInits memInitList,
1472 std::uint32_t attr)
1474 , memInits_(memInitList)
1475 {
1476 }
1477
1479 {
1481 delete memInits_.blob;
1482 else
1483 delete memInits_.memInitList;
1484 }
1485
1486 bool isCopyConstructor();
1487 bool isMoveConstructor();
1488
1489 void accept(CppVisitorBase* v) override
1490 {
1491 VISIT_COND(v->visit(this));
1492 if (params_ != nullptr)
1493 {
1494 for (auto& p : *params_)
1495 {
1496 p->accept(v);
1497 }
1498 }
1499 }
1500
1501private:
1502 mutable TriStateBool isCopyConstructor_ = TriStateBool::Unknown;
1503 mutable TriStateBool isMoveConstructor_ = TriStateBool::Unknown;
1504};
1505
1507
1509{
1510 static constexpr CppObjType kObjectType = CppObjType::kDestructor;
1511
1512 CppDestructor(CppAccessType accessType, std::string name, std::uint32_t attr)
1514 {
1515 }
1516
1517 void accept(CppVisitorBase* v) override
1518 {
1519 VISIT_COND(v->visit(this));
1520 }
1521};
1522
1524
1526{
1527 static constexpr CppObjType kObjectType = CppObjType::kTypeConverter;
1528
1530
1532 : CppFunctionBase(kObjectType, type->accessType_, std::move(name), 0)
1533 , to_(type)
1534 {
1535 }
1536
1537 void accept(CppVisitorBase* v) override
1538 {
1539 VISIT_COND(v->visit(this));
1540 if (to_ != nullptr)
1541 VISIT_COND(v->visit(to_.get()));
1542 }
1543};
1544
1546
1548{
1549 static constexpr CppObjType kObjectType = CppObjType::kUsingNamespaceDecl;
1550
1551 std::string name_;
1552
1555 , name_(std::move(name))
1556 {
1557 }
1558
1559 void accept(CppVisitorBase* v) override
1560 {
1561 VISIT_COND(v->visit(this));
1562 }
1563};
1564
1566
1567struct CppUsingDecl : public CppObj
1568{
1569 static constexpr CppObjType kObjectType = CppObjType::kUsingDecl;
1570
1571 std::string name_;
1573
1574 CppUsingDecl(std::string name, CppVarType* varType)
1575 : CppObj(kObjectType, varType->accessType_)
1576 , name_(std::move(name))
1577 , cppObj_(varType)
1578 {
1579 }
1580
1583 , name_(std::move(name))
1584 , cppObj_(fptr)
1585 {
1586 }
1587
1588 CppUsingDecl(std::string name, CppCompound* compound)
1589 : CppObj(kObjectType, compound->accessType_)
1590 , name_(std::move(name))
1591 , cppObj_(compound)
1592 {
1593 }
1594
1597 , name_(std::move(name))
1598 {
1599 }
1600
1602 {
1603 return templSpec_.get();
1604 }
1606 {
1607 templSpec_.reset(templParamList);
1608 }
1609
1610 void accept(CppVisitorBase* v) override
1611 {
1612 VISIT_COND(v->visit(this));
1613 if (cppObj_ != nullptr)
1614 cppObj_->accept(v);
1615 // `templSpec_` is not an AST node, it is a member of `CppUsingDecl`
1616 }
1617
1618private:
1620};
1621
1623
1625{
1626 static constexpr CppObjType kObjectType = CppObjType::kNamespaceAlias;
1627
1628 std::string name_;
1629 std::string alias_;
1630
1631 CppNamespaceAlias(std::string name, std::string alias)
1633 , name_(std::move(name))
1634 , alias_(std::move(alias))
1635 {
1636 }
1637
1638 void accept(CppVisitorBase* v) override
1639 {
1640 VISIT_COND(v->visit(this));
1641 }
1642};
1643
1645
1646struct CppDocComment : public CppObj
1647{
1648 static constexpr CppObjType kObjectType = CppObjType::kDocComment;
1649
1650 std::string doc_;
1651
1652 CppDocComment(std::string doc, CppAccessType objAccessType = CppAccessType::kUnknown)
1653 : CppObj(kObjectType, objAccessType)
1654 , doc_(std::move(doc))
1655 {
1656 }
1657
1658 void accept(CppVisitorBase* v) override
1659 {
1660 VISIT_COND(v->visit(this));
1661 }
1662};
1663
1665
1666struct CppExpr;
1671{
1672 union
1673 {
1674 std::string* atom;
1678 };
1679
1680 enum
1681 {
1686 kVarType
1688
1689 bool isExpr()
1690 {
1691 return (type & kExpr) == kExpr;
1692 }
1693
1694 CppExprAtom(char* sz, size_t l)
1695 : atom(new std::string(sz, l))
1696 , type(kAtom)
1697 {
1698 }
1699 CppExprAtom(char* sz)
1700 : atom(new std::string(sz))
1701 , type(kAtom)
1702 {
1703 }
1704 CppExprAtom(std::string tok)
1705 : atom(new std::string(std::move(tok)))
1706 , type(kAtom)
1707 {
1708 }
1710 : expr(e)
1711 , type(kExpr)
1712 {
1713 }
1715 : lambda(l)
1716 , type(kLambda)
1717 {
1718 }
1720 : varType(vType)
1721 , type(kVarType)
1722 {
1723 }
1725 : atom(nullptr)
1726 , type(kInvalid)
1727 {
1728 }
1732 void destroy();
1733};
1734
1749struct CppExpr : public CppObj
1750{
1751 static constexpr CppObjType kObjectType = CppObjType::kExpression;
1752
1753 enum Flag
1754 {
1755 kReturn = 0x01,
1756 kNew = 0x02,
1757 // kNewArray = 0x04, // This is not needed.
1758 kDelete = 0x08,
1762 kThrow = 0x80,
1763 kSizeOf = 0x100,
1765 kGoto = 0x400,
1766 };
1767
1772 short flags_; // ORed combination of Flag constants.
1773
1775 : CppExpr(e1, op, e2, 0)
1776 {
1777 }
1778
1779 CppExpr(CppExprAtom e1, short flags)
1780 : CppExpr(e1, kNone, CppExprAtom(), flags)
1781 {
1782 }
1783
1784 // CppExpr(CppExprAtom e1, CppOperator op, short flags)
1785 // : CppExpr(e1, op, CppExprAtom(), flags)
1786 // {
1787 // }
1788
1791 , expr1_(e1)
1792 , expr2_(e2)
1793 , oper_(op)
1794 , flags_(flags)
1795 {
1796 }
1797
1800 , expr1_(e1)
1801 , expr2_(e2)
1802 , expr3_(e3)
1804 , flags_(0)
1805 {
1806 }
1807
1808 CppExpr(std::string name)
1809 : CppExpr(CppExprAtom(std::move(name)), CppOperator::kNone)
1810 {
1811 }
1812
1815 , expr1_(l)
1816 , oper_(kNone)
1817 , flags_(0)
1818 {
1819 }
1820
1821 ~CppExpr() override
1822 {
1823 expr1_.destroy();
1824 expr2_.destroy();
1825 expr3_.destroy();
1826 }
1827
1828 void accept(CppVisitorBase* v) override
1829 {
1830 // std::cout<<"\naccept expr "<< this << "\n";
1831 VISIT_COND(v->visit(this));
1832 for (int i = 0; i < 3; i++)
1833 {
1834 auto* p = i == 0 ? &expr1_ : i == 1 ? &expr2_ : i == 2 ? &expr3_ : nullptr;
1835 if (p->expr == nullptr) // it's a union, p->expr == null means the whole thing is null.
1836 continue;
1837 switch (p->type)
1838 {
1839 case CppExprAtom::kExpr: {
1840 // std::cout<<"\naccept expr sub expr"<< i <<" "<< this << "\n";
1841 p->expr->accept(v);
1842 break;
1843 }
1844 case CppExprAtom::kLambda: {
1845 // std::cout<<"\naccept expr sub lambda"<< i <<" "<< this << "\n";
1846 p->lambda->accept(v);
1847 break;
1848 }
1849 case CppExprAtom::kVarType: {
1850 // std::cout<<"\naccept expr sub varType"<< i <<" "<< this << "\n";
1851 VISIT_COND(v->visit(p->varType));
1852 break;
1853 }
1854 default: { // Atom (is not an AST node) and Invalid
1855 break;
1856 }
1857 }
1858 }
1859 }
1860};
1861
1863
1865
1867{
1868 std::string name_;
1870
1871 CppEnumItem(std::string name, CppExpr* val = nullptr)
1872 : name_(std::move(name))
1873 , val_(val)
1874 {
1875 }
1876
1878 : val_(anyItem)
1879 {
1880 }
1881};
1882
1883using CppEnumItemList = std::list<CppEnumItem*>;
1884using CppEnumItemListPtr = std::unique_ptr<CppEnumItemList>;
1885
1886struct CppEnum : public CppObj
1887{
1888 static constexpr CppObjType kObjectType = CppObjType::kEnum;
1889
1890 std::string name_; // Can be empty for anonymous enum.
1891 CppEnumItemListPtr itemList_; // Can be nullptr for forward declared enum.
1893 std::string underlyingType_;
1894
1896 std::string name,
1897 CppEnumItemList* itemList,
1898 bool isClass = false,
1899 std::string underlyingType = std::string())
1901 , name_(std::move(name))
1902 , itemList_(itemList)
1903 , isClass_(isClass)
1904 , underlyingType_(std::move(underlyingType))
1905 {
1906 }
1907
1908 void accept(CppVisitorBase* v) override
1909 {
1910 VISIT_COND(v->visit(this));
1911 // `CppEnumItemListPtr` is a vector of base type `CppEnumItem` which is not an AST node type.
1912 // but that type contains `CppObjPtr`, idk, maybe `itemList_` should be included here.
1914 }
1915};
1916
1918
1921template <CppObjType _ObjType>
1922struct CppCommonBlock : public CppObj
1923{
1924 static constexpr CppObjType kObjectType = _ObjType;
1925
1927 : CppObj(_ObjType, CppAccessType::kUnknown)
1928 , cond_(cond)
1929 , body_(body)
1930 {
1931 }
1932
1935
1936 void accept(CppVisitorBase* v) override
1937 {
1938 VISIT_COND(v->visit(this));
1939 if (cond_ != nullptr)
1940 cond_->accept(v);
1941 if (body_ != nullptr)
1942 body_->accept(v);
1943 }
1944};
1945
1946struct CppIfBlock : public CppCommonBlock<CppObjType::kIfBlock>
1947{
1948 CppIfBlock(CppObj* cond, CppObj* body, CppObj* _else = nullptr)
1949 : CppCommonBlock(cond, body)
1950 , else_ {_else}
1951 {
1952 }
1954 {
1955 return else_.get();
1956 }
1957 void elsePart(CppObj* _elsePart)
1958 {
1959 else_.reset(_elsePart);
1960 }
1961
1962 void accept(CppVisitorBase* v) override
1963 {
1964 VISIT_COND(v->visit(this));
1965 if (cond_ != nullptr)
1966 cond_->accept(v); // assuming that `cond_` pointer cannot be nullptr ever.
1967 if (body_ != nullptr)
1968 body_->accept(v);
1969 if (else_ != nullptr)
1970 else_->accept(v);
1971 }
1972
1973private:
1975};
1976
1978
1981
1984
1985struct CppForBlock : public CppObj
1986{
1987 static constexpr CppObjType kObjectType = CppObjType::kForBlock;
1988
1993
1994 CppForBlock(CppObj* start, CppExpr* stop, CppExpr* step, CppObj* body)
1996 , start_(start)
1997 , stop_(stop)
1998 , step_(step)
1999 , body_(body)
2000 {
2001 }
2002
2003 void accept(CppVisitorBase* v) override
2004 {
2005 VISIT_COND(v->visit(this));
2006 if (start_ != nullptr)
2007 start_->accept(v);
2008 if (stop_ != nullptr)
2009 VISIT_COND(v->visit(stop_.get()));
2010 if (step_ != nullptr)
2011 VISIT_COND(v->visit(step_.get()));
2012 if (body_ != nullptr)
2013 body_->accept(v);
2014 }
2015};
2016
2018{
2019 static constexpr CppObjType kObjectType = CppObjType::kRangeForBlock;
2020
2024
2027 , var_(var)
2028 , expr_(expr)
2029 , body_(body)
2030 {
2031 }
2032
2033 void accept(CppVisitorBase* v) override
2034 {
2035 VISIT_COND(v->visit(this));
2036 if (var_ != nullptr)
2037 VISIT_COND(v->visit(var_.get()));
2038 if (expr_ != nullptr)
2039 VISIT_COND(v->visit(expr_.get()));
2040 if (body_ != nullptr)
2041 body_->accept(v);
2042 }
2043};
2044
2046
2048{
2050 : case_(cond)
2051 , body_(body)
2052 {
2053 }
2054
2057};
2058
2059using CppSwitchBody = std::vector<CppCase>;
2060using CppSwitchBodyPtr = std::unique_ptr<CppSwitchBody>;
2061
2062struct CppSwitchBlock : public CppObj
2063{
2064 static constexpr CppObjType kObjectType = CppObjType::kSwitchBlock;
2065
2068
2071 , cond_(cond)
2072 , body_(body)
2073 {
2074 }
2075
2076 void accept(CppVisitorBase* v) override
2077 {
2078 VISIT_COND(v->visit(this));
2079 if (cond_ != nullptr)
2080 VISIT_COND(v->visit(cond_.get()));
2081 for (auto& c : *body_)
2082 {
2083 if (c.case_ != nullptr)
2084 VISIT_COND(v->visit(c.case_.get()));
2085 if (c.body_ != nullptr)
2086 c.body_->accept(v);
2087 }
2088 }
2089};
2090
2092
2094{
2096 std::string exceptionName_;
2098};
2099
2100using CppCatchBlockPtr = std::unique_ptr<CppCatchBlock>;
2101
2102using CppCatchBlocks = std::vector<CppCatchBlockPtr>;
2103
2104struct CppTryBlock : public CppObj
2105{
2106 static constexpr CppObjType kObjectType = CppObjType::kTryBlock;
2108
2109 CppTryBlock(CppCompound* tryStmt, CppCatchBlock* firstCatchBlock)
2111 , tryStmt_(tryStmt)
2112 {
2113 catchBlocks_.emplace_back(firstCatchBlock);
2114 }
2115
2117 {
2118 catchBlocks_.emplace_back(catchBlock);
2119 }
2120
2121 void accept(CppVisitorBase* v) override
2122 {
2123 VISIT_COND(v->visit(this));
2124 if (tryStmt_ != nullptr)
2125 tryStmt_->accept(v); // a block of code
2126 for (auto& c : catchBlocks_)
2127 {
2128 if (c->exceptionType_ != nullptr)
2129 VISIT_COND(v->visit(c->exceptionType_.get()));
2130 // `c->exceptionName_` is string, not of an AST node type.
2131 if (c->catchStmt_ != nullptr)
2132 c->catchStmt_->accept(v); // a block of code
2133 }
2134 }
2135
2136private:
2138};
2139
2140// Templare argument needs more robust support.
2141// As of now we are treating them just as string.
2142// But for parsing we need to have a type.
2143struct CppTemplateArg;
2144
2145struct CppAsmBlock : public CppObj
2146{
2147 std::string asm_; // Entire asm block including keyword asm.
2148
2149 CppAsmBlock(std::string asmBlock)
2151 , asm_(std::move(asmBlock))
2152 {
2153 }
2154
2155 void accept(CppVisitorBase* v) override
2156 {
2157 VISIT_COND(v->visit(this));
2158 }
2159};
2160
2162
2164{
2165 switch (type)
2166 {
2167 case CppExprAtom::kAtom:
2168 delete atom;
2169 break;
2170 case CppExprAtom::kExpr:
2171 delete expr;
2172 break;
2174 delete varType;
2175 break;
2177 delete lambda;
2178 break;
2179
2180 default:
2181 break;
2182 }
2183}
2184
2185struct CppLabel : public CppObj
2186{
2187 static constexpr CppObjType kObjectType = CppObjType::kLabel;
2188
2189 std::string label_;
2190
2191 CppLabel(std::string label)
2193 , label_(std::move(label))
2194 {
2195 }
2196
2197 void accept(CppVisitorBase* v) override
2198 {
2199 VISIT_COND(v->visit(this));
2200 }
2201};
2202
2204
2205inline CppVarDecl::CppVarDecl(std::string name, CppExpr* assign, AssignType assignType)
2206 : name_(std::move(name))
2207 , assignValue_(assign)
2208 , assignType_(assignType)
2209{
2210}
2211
2213 : CppVarType(CppAccessType::kUnknown, std::move(baseType), modifier)
2214{
2215}
2216
2218 : CppVarType(accessType, std::move(baseType), 0, modifier)
2219{
2220}
2221
2223 : CppObj(kObjectType, accessType)
2224 , compound_(compound)
2225 , typeModifier_(modifier)
2226{
2227}
2228
2230 : CppObj(kObjectType, accessType)
2231 , compound_(compound)
2232 , typeModifier_(modifier)
2233{
2234}
2235
2237 : CppObj(kObjectType, accessType)
2238 , compound_(enumObj)
2239 , typeModifier_(modifier)
2240{
2241}
2242
2244 : CppVarType(varType.accessType_, varType.baseType(), varType.typeModifier())
2245{
2246 // TODO: clone compound_.
2247}
2248
2249inline CppTemplateParam::CppTemplateParam(CppFunctionPointer* paramType, std::string paramName)
2250 : paramType_(paramType)
2251 , paramName_(std::move(paramName))
2252{
2253}
2254
2256
2257
2258bool operator==(const CppExpr& expr1, const CppExpr& expr2);
2259
2260inline bool operator!=(const CppExpr& expr1, const CppExpr& expr2)
2261{
2262 return !(expr1 == expr2);
2263}
2264
2265inline bool operator==(const CppExprAtom& exprAtom1, const CppExprAtom& exprAtom2)
2266{
2267 if (exprAtom1.type != exprAtom2.type)
2268 return false;
2269 if (exprAtom1.type == CppExprAtom::kAtom)
2270 {
2271 return (*exprAtom1.atom) == (*exprAtom2.atom);
2272 }
2273 if (exprAtom1.type == CppExprAtom::kExpr)
2274 {
2275 return (*exprAtom1.expr) == (*exprAtom2.expr);
2276 }
2277 return false;
2278}
2279
2280inline bool operator!=(const CppExprAtom& exprAtom1, const CppExprAtom& exprAtom2)
2281{
2282 return !(exprAtom1 == exprAtom2);
2283}
Helps working with raw or unique_ptr of CppObj in a uniform way.
Definition: cppeasyptr.h:44
virtual bool visit(CppVarType *p)=0
The visitor pattern's visit methods for the given types.
bool operator==(const CppExpr &expr1, const CppExpr &expr2)
Definition: cppast.cpp:194
std::unique_ptr< CppTemplateParamList > CppTemplateParamListPtr
Definition: cppast.h:557
std::unique_ptr< CppSwitchBody > CppSwitchBodyPtr
Definition: cppast.h:2060
std::unique_ptr< CppExpr > CppExprPtr
Definition: cppast.h:391
std::pair< std::string, CppExpr * > CppMemInit
Class data member initialization as part of class constructor.
Definition: cppast.h:1425
std::list< CppEnumItem * > CppEnumItemList
Definition: cppast.h:1883
std::unique_ptr< CppVarType > CppVarTypePtr
Definition: cppast.h:553
std::unique_ptr< CppEnumItemList > CppEnumItemListPtr
Definition: cppast.h:1884
std::vector< std::unique_ptr< CppTemplateParam > > CppTemplateParamList
Definition: cppast.h:556
std::vector< CppObjPtr > CppParamVector
Definition: cppast.h:1253
CppIdentifierList CppFuncThrowSpec
Definition: cppast.h:1156
std::unique_ptr< CppFuncThrowSpec > CppFuncThrowSpecPtr
Definition: cppast.h:1158
#define VISIT_COND(CALL)
Definition: cppast.h:124
bool operator!=(const CppExpr &expr1, const CppExpr &expr2)
Definition: cppast.h:2260
CppExprPtr AttribSpecifier
Definition: cppast.h:392
std::unique_ptr< CppObj > CppObjPtr
Definition: cppast.h:417
std::unique_ptr< CppVarList > CppVarListPtr
Definition: cppast.h:757
std::vector< std::unique_ptr< CppObj > > CppObjPtrArray
Definition: cppast.h:914
std::vector< std::string > CppIdentifierList
Definition: cppast.h:1155
std::unique_ptr< AttribSpecifierArray > AttribSpecifierSequence
Definition: cppast.h:394
std::vector< CppExprPtr > CppArraySizes
Definition: cppast.h:492
std::unique_ptr< CppInheritanceList > CppInheritanceListPtr
Definition: cppast.h:913
std::vector< CppVarDeclInList > CppVarDeclList
Definition: cppast.h:693
std::vector< AttribSpecifier > AttribSpecifierArray
Definition: cppast.h:393
CppMemInits makeCppMemInitList(std::list< CppMemInit > *memInitList)
Definition: cppast.h:1445
std::vector< CppCase > CppSwitchBody
Definition: cppast.h:2059
std::unique_ptr< CppVar > CppVarPtr
Definition: cppast.h:681
std::unique_ptr< CppCatchBlock > CppCatchBlockPtr
Definition: cppast.h:2100
std::unique_ptr< CppCompound > CppCompoundPtr
Definition: cppast.h:416
CppMemInits makeEmptyCppMemInitList()
Definition: cppast.h:1440
std::list< CppInheritInfo > CppInheritanceList
Definition: cppast.h:912
std::vector< CppCatchBlockPtr > CppCatchBlocks
Definition: cppast.h:2102
std::unique_ptr< CppParamVector > CppParamVectorPtr
Definition: cppast.h:1254
bool isClass(CppCompoundEPtr compound)
CppAccessType
Definition: cppconst.h:103
AssignType
Definition: cppconst.h:222
TriStateBool
Definition: cppconst.h:29
CppObjType
Definition: cppconst.h:36
CppCompoundType
Definition: cppconst.h:90
CppOperator
Definition: cppconst.h:111
@ kNone
Definition: cppconst.h:112
@ kTertiaryOperator
Definition: cppconst.h:180
CppAccessType accessType(CppObj *cppObj)
std::vector< CppObjPtr > CppParamVector
Definition: cpptoken.h:110
std::unique_ptr< CppObj > CppObjPtr
Definition: cpptoken.h:109
std::string & baseType(CppVarType *varType)
std::string & name(CppVar *var)
std::string & trimBlob(std::string &s)
Definition: string-utils.h:42
std::string & cleanseIdentifier(std::string &id)
strips new-line char and collapses multiple white chars.
Definition: string-utils.h:68
A mixin class to allow objects to have attribute specifier sequence as described at https://en....
Definition: cppast.h:401
AttribSpecifierSequence attributeSpecifiers_
Definition: cppast.h:412
void attribSpecifierSequence(AttribSpecifierArray *attribSpecifierArray)
Definition: cppast.h:406
AttribSpecifierSequence & attribSpecifierSequence()
Definition: cppast.h:402
std::string asm_
Definition: cppast.h:2147
CppAsmBlock(std::string asmBlock)
Definition: cppast.h:2149
void accept(CppVisitorBase *v) override
Definition: cppast.h:2155
A stream of text that represents some content in a C++ program.
Definition: cppast.h:167
CppBlob(std::string blob)
Definition: cppast.h:171
std::string blob_
Definition: cppast.h:169
static constexpr CppObjType kObjectType
Definition: cppast.h:168
void accept(CppVisitorBase *v) override
Definition: cppast.h:177
CppCompoundPtr body_
Definition: cppast.h:2056
CppExprPtr case_
Definition: cppast.h:2055
CppCase(CppExpr *cond, CppCompound *body)
Definition: cppast.h:2049
CppVarTypePtr exceptionType_
Definition: cppast.h:2095
std::string exceptionName_
Definition: cppast.h:2096
CppCompoundPtr catchStmt_
Definition: cppast.h:2097
Some blocks have common structure like if, while, and do-while.
Definition: cppast.h:1923
static constexpr CppObjType kObjectType
Definition: cppast.h:1924
CppObjPtr body_
Definition: cppast.h:1934
CppCommonBlock(CppObj *cond, CppObj *body)
Definition: cppast.h:1926
CppObjPtr cond_
Definition: cppast.h:1933
void accept(CppVisitorBase *v) override
Definition: cppast.h:1936
All classes, structs, unions, and namespaces can be classified as a Compound object.
Definition: cppast.h:927
std::string apidecor_
Definition: cppast.h:1138
CppObjPtrArray members_
Definition: cppast.h:1136
CppTemplateParamList * templateParamList()
Definition: cppast.h:996
void addMemberAtFront(CppObj *mem)
Definition: cppast.h:1041
CppObjPtrArray & members()
Definition: cppast.h:982
CppCompound(std::string name, CppCompoundType type)
Definition: cppast.h:943
std::vector< CppConstructor * > ctors_
Definition: cppast.h:1142
static constexpr CppObjType kObjectType
Definition: cppast.h:928
void accept(CppVisitorBase *v) override
Definition: cppast.h:1105
std::string justName()
Definition: cppast.h:961
TriStateBool hasVirtual_
Definition: cppast.h:1147
bool hasPureVirtual()
Definition: cppast.cpp:126
CppConstructor * copyCtor()
Definition: cppast.h:1072
bool triviallyConstructable()
Definition: cppast.cpp:160
CppTemplateParamListPtr templSpec_
Definition: cppast.h:1139
CppObjPtr deassocMemberAt(size_t idx)
Definition: cppast.h:1054
std::vector< CppConstructor * > & ctors()
Definition: cppast.h:1080
bool hasAttr(std::uint32_t _attr)
Definition: cppast.h:1095
bool hasASingleBlobMember()
Definition: cppast.h:1100
CppConstructor * copyCtor_
Definition: cppast.h:1143
bool hasPublicVirtualMethod()
Definition: cppast.cpp:102
std::string name_
Definition: cppast.h:1134
void assignSpecialMember(CppObj *mem)
Definition: cppast.cpp:172
void name(std::string _name)
Definition: cppast.h:957
CppInheritanceListPtr inheritanceList_
Definition: cppast.h:1137
void inheritanceList(CppInheritanceList *_inheritanceList)
Definition: cppast.h:1017
void addBaseClass(std::string baseName, CppAccessType inheritType)
Definition: cppast.h:1063
std::string & name()
Definition: cppast.h:953
CppDestructor * dtor()
Definition: cppast.h:1084
CppCompound(CppAccessType accessType, CppCompoundType type=CppCompoundType::kUnknownCompound)
Definition: cppast.h:938
void addMemberAt(CppObjPtr &&mem, unsigned index)
Definition: cppast.h:1034
void addAttr(std::uint32_t _attr)
Definition: cppast.h:1090
void compoundType(CppCompoundType compoundType)
Definition: cppast.h:973
std::uint32_t attr_
Definition: cppast.h:1140
std::string & apidecor()
Definition: cppast.h:987
void addMemberAtFront(CppObjPtr &&mem)
Definition: cppast.h:1047
CppConstructor * moveCtor_
Definition: cppast.h:1144
void apidecor(std::string apidecor)
Definition: cppast.h:991
void templateParamList(CppTemplateParamList *_templateParamList)
Definition: cppast.h:1004
CppCompoundType compoundType()
Definition: cppast.h:969
CppCompound(CppCompoundType type)
Definition: cppast.h:948
CppInheritanceListPtr & inheritanceList()
Definition: cppast.h:1009
TriStateBool hasPureVirtual_
Definition: cppast.h:1148
CppCompoundType compoundType_
Definition: cppast.h:1135
void addMember(CppObj *mem)
Definition: cppast.h:1022
CppDestructor * dtor_
Definition: cppast.h:1145
void addMember(CppObjPtr &&mem)
Definition: cppast.h:1028
void templateParamList(CppTemplateParamListPtr _templateParamList)
Definition: cppast.h:1000
CppConstructor * moveCtor()
Definition: cppast.h:1076
void inheritanceList(CppInheritanceListPtr _inheritanceList)
Definition: cppast.h:1013
CppCompound(std::string name, CppAccessType accessType, CppCompoundType type)
Definition: cppast.h:930
bool isCopyConstructor()
Definition: cppast.cpp:32
void accept(CppVisitorBase *v) override
Definition: cppast.h:1489
CppMemInits memInits_
Definition: cppast.h:1466
TriStateBool isCopyConstructor_
Definition: cppast.h:1502
bool isMoveConstructor()
Definition: cppast.cpp:66
~CppConstructor() override
Definition: cppast.h:1478
static constexpr CppObjType kObjectType
Definition: cppast.h:1464
TriStateBool isMoveConstructor_
Definition: cppast.h:1503
CppConstructor(CppAccessType accessType, std::string name, CppParamVector *params, CppMemInits memInitList, std::uint32_t attr)
Definition: cppast.h:1468
CppDefine(DefType defType, std::string name, std::string defn=std::string())
Definition: cppast.h:196
void accept(CppVisitorBase *v) override
Definition: cppast.h:204
static constexpr CppObjType kObjectType
Definition: cppast.h:182
DefType defType_
Definition: cppast.h:192
std::string defn_
This will contain everything after name.
Definition: cppast.h:194
@ kRename
Definition: cppast.h:186
@ kComplexMacro
Definition: cppast.h:190
@ kConstStrDef
Definition: cppast.h:188
@ kConstCharDef
Definition: cppast.h:189
@ kConstNumDef
Definition: cppast.h:187
std::string name_
Definition: cppast.h:193
CppDestructor(CppAccessType accessType, std::string name, std::uint32_t attr)
Definition: cppast.h:1512
static constexpr CppObjType kObjectType
Definition: cppast.h:1510
void accept(CppVisitorBase *v) override
Definition: cppast.h:1517
std::string doc_
Entire comment text.
Definition: cppast.h:1650
CppDocComment(std::string doc, CppAccessType objAccessType=CppAccessType::kUnknown)
Definition: cppast.h:1652
static constexpr CppObjType kObjectType
Definition: cppast.h:1648
void accept(CppVisitorBase *v) override
Definition: cppast.h:1658
std::string name_
Definition: cppast.h:1868
CppObjPtr val_
Definition: cppast.h:1869
CppEnumItem(std::string name, CppExpr *val=nullptr)
Definition: cppast.h:1871
CppEnumItem(CppObj *anyItem)
Definition: cppast.h:1877
void accept(CppVisitorBase *v) override
Definition: cppast.h:1908
static constexpr CppObjType kObjectType
Definition: cppast.h:1888
std::string underlyingType_
Definition: cppast.h:1893
std::string name_
Definition: cppast.h:1890
bool isClass_
Definition: cppast.h:1892
CppEnumItemListPtr itemList_
Definition: cppast.h:1891
CppEnum(CppAccessType accessType, std::string name, CppEnumItemList *itemList, bool isClass=false, std::string underlyingType=std::string())
Definition: cppast.h:1895
An individual expression.
Definition: cppast.h:1671
std::string * atom
Definition: cppast.h:1674
CppExprAtom(CppVarType *vType)
Definition: cppast.h:1719
CppLambda * lambda
Definition: cppast.h:1676
CppExprAtom(CppExpr *e)
Definition: cppast.h:1709
enum CppExprAtom::@4 type
CppExprAtom(CppLambda *l)
Definition: cppast.h:1714
void destroy()
It is expected to be called explicitly to destroy an CppExprAtom object.
Definition: cppast.h:2163
CppExprAtom()
Definition: cppast.h:1724
CppVarType * varType
For type cast, and sizeof expression.
Definition: cppast.h:1677
CppExprAtom(char *sz)
Definition: cppast.h:1699
CppExprAtom(std::string tok)
Definition: cppast.h:1704
bool isExpr()
Definition: cppast.h:1689
CppExprAtom(char *sz, size_t l)
Definition: cppast.h:1694
CppExpr * expr
Definition: cppast.h:1675
An expression in a C/C++ program.
Definition: cppast.h:1750
CppExprAtom expr1_
Definition: cppast.h:1768
CppExpr(CppExprAtom e1, short flags)
Definition: cppast.h:1779
CppExpr(CppExprAtom e1, CppOperator op, CppExprAtom e2, short flags)
Definition: cppast.h:1789
CppExpr(CppLambda *l)
Definition: cppast.h:1813
@ kInitializer
Definition: cppast.h:1761
@ kThrow
Definition: cppast.h:1762
@ kDelete
Definition: cppast.h:1758
@ kGoto
Definition: cppast.h:1765
@ kBracketed
Definition: cppast.h:1760
@ kDeleteArray
Definition: cppast.h:1759
@ kSizeOf
Definition: cppast.h:1763
@ kNew
Definition: cppast.h:1756
@ kReturn
Definition: cppast.h:1755
@ kVariadicPack
Definition: cppast.h:1764
CppExprAtom expr3_
Definition: cppast.h:1770
CppOperator oper_
Definition: cppast.h:1771
static constexpr CppObjType kObjectType
Definition: cppast.h:1751
CppExpr(CppExprAtom e1, CppOperator op, CppExprAtom e2=CppExprAtom())
Definition: cppast.h:1774
void accept(CppVisitorBase *v) override
Definition: cppast.h:1828
CppExpr(CppExprAtom e1, CppExprAtom e2, CppExprAtom e3)
Definition: cppast.h:1798
CppExpr(std::string name)
Definition: cppast.h:1808
~CppExpr() override
Definition: cppast.h:1821
CppExprAtom expr2_
Definition: cppast.h:1769
short flags_
Definition: cppast.h:1772
CppForBlock(CppObj *start, CppExpr *stop, CppExpr *step, CppObj *body)
Definition: cppast.h:1994
CppExprPtr stop_
Definition: cppast.h:1990
CppExprPtr step_
Definition: cppast.h:1991
void accept(CppVisitorBase *v) override
Definition: cppast.h:2003
CppObjPtr body_
Definition: cppast.h:1992
static constexpr CppObjType kObjectType
Definition: cppast.h:1987
CppObjPtr start_
Definition: cppast.h:1989
CppFuncCtorBase(CppObjType type, CppAccessType accessType, std::string name, CppParamVector *params, std::uint32_t attr)
Definition: cppast.h:1269
CppParamVectorPtr params_
Definition: cppast.h:1280
CppParamVector * params()
Definition: cppast.h:1263
bool hasParams()
Definition: cppast.h:1258
CppFuncThrowSpecPtr throwSpec_
Definition: cppast.h:1188
void throwSpec(CppFuncThrowSpec *_throwSpec)
Definition: cppast.h:1166
CppFuncLikeBase(CppObjType type, CppAccessType accessType)
Definition: cppast.h:1181
CppFuncThrowSpec * throwSpec()
Definition: cppast.h:1162
CppCompoundPtr defn_
Definition: cppast.h:1187
void defn(CppCompound *_defn)
Definition: cppast.h:1175
CppCompound * defn()
Definition: cppast.h:1171
Base class of constructor, destructor, and functions.
Definition: cppast.h:1195
bool hasAttr(std::uint32_t _attr)
Definition: cppast.h:1206
std::uint32_t attr_
Definition: cppast.h:1247
void templateParamList(CppTemplateParamList *templParamList)
Definition: cppast.h:1233
std::string decor2_
Definition: cppast.h:1249
std::string & decor1()
Definition: cppast.h:1211
CppTemplateParamList * templateParamList()
Definition: cppast.h:1229
void addAttr(std::uint32_t _attr)
Definition: cppast.h:1202
void decor1(std::string _decor)
Definition: cppast.h:1215
std::string name_
Definition: cppast.h:1196
std::string & decor2()
Definition: cppast.h:1220
std::uint32_t attr()
Definition: cppast.h:1198
CppTemplateParamListPtr templSpec_
Definition: cppast.h:1250
std::string decor1_
Definition: cppast.h:1248
CppFunctionBase(CppObjType type, CppAccessType accessType, std::string name, std::uint32_t attr)
Definition: cppast.h:1239
void decor2(std::string _decor)
Definition: cppast.h:1224
Function pointer type definition using typedef, e.g.
Definition: cppast.h:1390
void accept(CppVisitorBase *v) override
Definition: cppast.h:1406
static constexpr CppObjType kObjectType
Definition: cppast.h:1391
std::string ownerName_
Definition: cppast.h:1393
CppFunctionPointer(CppAccessType accessType, std::string name, CppVarType *retType, CppParamVector *params, std::uint32_t attr, std::string ownerName=std::string())
Definition: cppast.h:1395
CppFunction(CppObjType type, CppAccessType accessType, std::string name, CppVarType *retType, CppParamVector *params, std::uint32_t attr)
Definition: cppast.h:1333
static unsigned findMainFunctionFromMembers(const CppObjPtrArray &members)
Definition: cppast.h:1302
CppVarTypePtr retType_
Definition: cppast.h:1290
CppFunction(CppAccessType accessType, std::string name, CppVarType *retType, CppParamVector *params, std::uint32_t attr)
Definition: cppast.h:1292
void accept(CppVisitorBase *v) override
Definition: cppast.h:1317
static constexpr CppObjType kObjectType
Definition: cppast.h:1288
CppCompoundType cmpType_
Definition: cppast.h:861
std::uint32_t attr()
Definition: cppast.h:882
CppFwdClsDecl(CppAccessType accessType, std::string name, CppCompoundType cmpType=CppCompoundType::kNoCompound)
Definition: cppast.h:877
CppFwdClsDecl(CppAccessType accessType, std::string name, std::string apidecor, CppCompoundType cmpType=CppCompoundType::kNoCompound)
Definition: cppast.h:865
std::string name_
Definition: cppast.h:862
CppTemplateParamList * templateParamList()
Definition: cppast.h:891
void accept(CppVisitorBase *v) override
Definition: cppast.h:900
static constexpr CppObjType kObjectType
Definition: cppast.h:859
CppTemplateParamListPtr templSpec_
Definition: cppast.h:906
void templateParamList(CppTemplateParamList *templParamList)
Definition: cppast.h:895
std::string apidecor_
Definition: cppast.h:863
void addAttr(std::uint32_t _attr)
Definition: cppast.h:886
std::uint32_t attr_
Definition: cppast.h:907
static constexpr CppObjType kObjectType
Definition: cppast.h:329
void accept(CppVisitorBase *v) override
Definition: cppast.h:339
std::string err_
Definition: cppast.h:331
CppHashError(std::string err)
Definition: cppast.h:333
Represents all variants of #if preprocessors.
Definition: cppast.h:276
CppHashIf(CondType condType, std::string cond=std::string())
Definition: cppast.h:292
static constexpr CppObjType kObjectType
Definition: cppast.h:277
void accept(CppVisitorBase *v) override
Definition: cppast.h:299
CondType condType_
Definition: cppast.h:289
std::string cond_
Definition: cppast.h:290
@ kElse
Definition: cppast.h:284
@ kEndIf
Definition: cppast.h:286
@ kIfNDef
Definition: cppast.h:283
@ kElIf
Definition: cppast.h:285
@ kIfDef
Definition: cppast.h:282
CppHashWarning(std::string err)
Definition: cppast.h:353
std::string err_
Definition: cppast.h:351
void accept(CppVisitorBase *v) override
Definition: cppast.h:359
static constexpr CppObjType kObjectType
Definition: cppast.h:349
void elsePart(CppObj *_elsePart)
Definition: cppast.h:1957
CppObj * elsePart()
Definition: cppast.h:1953
CppIfBlock(CppObj *cond, CppObj *body, CppObj *_else=nullptr)
Definition: cppast.h:1948
CppObjPtr else_
Definition: cppast.h:1974
void accept(CppVisitorBase *v) override
Definition: cppast.h:1962
static constexpr CppObjType kObjectType
Definition: cppast.h:252
std::string name_
Definition: cppast.h:254
void accept(CppVisitorBase *v) override
Definition: cppast.h:262
CppImport(std::string name)
Definition: cppast.h:256
void accept(CppVisitorBase *v) override
Definition: cppast.h:244
std::string name_
Definition: cppast.h:236
static constexpr CppObjType kObjectType
Definition: cppast.h:234
CppInclude(std::string name)
Definition: cppast.h:238
CppInheritInfo(std::string _baseName, CppAccessType _inhType, bool virtualInheritance=false)
Definition: cppast.h:810
CppAccessType inhType
Definition: cppast.h:807
bool isVirtual
Definition: cppast.h:808
std::string baseName
Definition: cppast.h:806
CppLabel(std::string label)
Definition: cppast.h:2191
void accept(CppVisitorBase *v) override
Definition: cppast.h:2197
std::string label_
Definition: cppast.h:2189
static constexpr CppObjType kObjectType
Definition: cppast.h:2187
CppCompoundPtr defn_
Definition: cppast.h:1352
CppLambda(CppExpr *captures, CppParamVector *params, CppCompound *defn, CppVarType *retType=nullptr)
Definition: cppast.h:1354
CppVarTypePtr retType_
Definition: cppast.h:1351
CppParamVectorPtr params_
Definition: cppast.h:1350
CppExprPtr captures_
Definition: cppast.h:1349
void accept(CppVisitorBase *v) override
Definition: cppast.h:1363
static constexpr CppObjType kObjectType
Definition: cppast.h:1347
std::string macroCall_
Definition: cppast.h:786
void accept(CppVisitorBase *v) override
Definition: cppast.h:794
static constexpr CppObjType kObjectType
Definition: cppast.h:784
CppMacroCall(std::string macroCall, CppAccessType accessType)
Definition: cppast.h:788
Entire member initialization list.
Definition: cppast.h:1431
bool memInitListIsABlob_
Definition: cppast.h:1432
std::list< CppMemInit > * memInitList
Definition: cppast.h:1435
CppBlob * blob
Definition: cppast.h:1436
std::string alias_
Definition: cppast.h:1629
std::string name_
Definition: cppast.h:1628
static constexpr CppObjType kObjectType
Definition: cppast.h:1626
CppNamespaceAlias(std::string name, std::string alias)
Definition: cppast.h:1631
void accept(CppVisitorBase *v) override
Definition: cppast.h:1638
An abstract class that is used as base class of all other classes.
Definition: cppast.h:134
CppObj(CppObjType type, CppAccessType accessType)
Definition: cppast.h:138
virtual void accept(CppVisitorBase *v)=0
virtual ~CppObj()
Definition: cppast.h:157
void owner(CppCompound *o)
Definition: cppast.h:149
CppCompound * owner()
Definition: cppast.h:145
CppAccessType accessType_
All objects do not need this.
Definition: cppast.h:136
CppObjType objType_
Definition: cppast.h:135
CppCompound * owner_
Definition: cppast.h:160
void accept(CppVisitorBase *v) override
Definition: cppast.h:319
CppPragma(std::string defn)
Definition: cppast.h:313
std::string defn_
Definition: cppast.h:311
static constexpr CppObjType kObjectType
Definition: cppast.h:309
void accept(CppVisitorBase *v) override
Definition: cppast.h:2033
CppObjPtr body_
Definition: cppast.h:2023
static constexpr CppObjType kObjectType
Definition: cppast.h:2019
CppExprPtr expr_
Definition: cppast.h:2022
CppVarPtr var_
Definition: cppast.h:2021
CppRangeForBlock(CppVar *var, CppExpr *expr, CppObj *body)
Definition: cppast.h:2025
CppSwitchBodyPtr body_
Definition: cppast.h:2067
void accept(CppVisitorBase *v) override
Definition: cppast.h:2076
static constexpr CppObjType kObjectType
Definition: cppast.h:2064
CppExprPtr cond_
Definition: cppast.h:2066
CppSwitchBlock(CppExpr *cond, CppSwitchBody *body)
Definition: cppast.h:2069
Parameter types that are used to define a template class or function.
Definition: cppast.h:823
CppTemplateParam(CppVarType *paramType, std::string paramName)
Definition: cppast.h:834
std::unique_ptr< CppObj > paramType_
Definition: cppast.h:825
CppTemplateParam(std::string paramName)
Definition: cppast.h:828
CppObjPtr defaultArg_
Definition: cppast.h:854
CppObj * defaultArg()
Definition: cppast.h:842
std::string paramName_
Definition: cppast.h:826
void defaultArg(CppObj *defParam)
Definition: cppast.h:847
static constexpr CppObjType kObjectType
Definition: cppast.h:2106
void addCatchBlock(CppCatchBlock *catchBlock)
Definition: cppast.h:2116
CppTryBlock(CppCompound *tryStmt, CppCatchBlock *firstCatchBlock)
Definition: cppast.h:2109
CppCompoundPtr tryStmt_
Definition: cppast.h:2107
void accept(CppVisitorBase *v) override
Definition: cppast.h:2121
CppCatchBlocks catchBlocks_
Definition: cppast.h:2137
static constexpr CppObjType kObjectType
Definition: cppast.h:1527
CppVarTypePtr to_
Definition: cppast.h:1529
CppTypeConverter(CppVarType *type, std::string name)
Definition: cppast.h:1531
void accept(CppVisitorBase *v) override
Definition: cppast.h:1537
std::uint32_t constBits_
Definition: typemodifier.h:47
void accept(CppVisitorBase *v) override
Definition: cppast.h:772
CppVarListPtr varList_
Definition: cppast.h:764
CppTypedefList(CppVarList *varList)
Definition: cppast.h:766
static constexpr CppObjType kObjectType
Definition: cppast.h:762
static constexpr CppObjType kObjectType
Definition: cppast.h:737
CppVarPtr var_
Definition: cppast.h:739
void accept(CppVisitorBase *v) override
Definition: cppast.h:747
CppTypedefName(CppVar *var)
Definition: cppast.h:741
Any other C/C++ preprocessor for which there is no class defined.
Definition: cppast.h:371
void accept(CppVisitorBase *v) override
Definition: cppast.h:384
CppUnRecogPrePro(std::string name, std::string defn)
Definition: cppast.h:377
std::string defn_
Definition: cppast.h:375
std::string name_
Definition: cppast.h:374
static constexpr CppObjType kObjectType
Definition: cppast.h:372
CppUndef(std::string name)
Definition: cppast.h:218
void accept(CppVisitorBase *v) override
Definition: cppast.h:224
std::string name_
Definition: cppast.h:216
static constexpr CppObjType kObjectType
Definition: cppast.h:214
CppObjPtr cppObj_
Definition: cppast.h:1572
CppUsingDecl(std::string name, CppFunctionPointer *fptr)
Definition: cppast.h:1581
void accept(CppVisitorBase *v) override
Definition: cppast.h:1610
CppUsingDecl(std::string name, CppVarType *varType)
Definition: cppast.h:1574
CppUsingDecl(std::string name, CppAccessType accessType)
Definition: cppast.h:1595
CppUsingDecl(std::string name, CppCompound *compound)
Definition: cppast.h:1588
std::string name_
Definition: cppast.h:1571
static constexpr CppObjType kObjectType
Definition: cppast.h:1569
CppTemplateParamList * templateParamList()
Definition: cppast.h:1601
CppTemplateParamListPtr templSpec_
Definition: cppast.h:1619
void templateParamList(CppTemplateParamList *templParamList)
Definition: cppast.h:1605
CppUsingNamespaceDecl(std::string name)
Definition: cppast.h:1553
void accept(CppVisitorBase *v) override
Definition: cppast.h:1559
std::string name_
Definition: cppast.h:1551
static constexpr CppObjType kObjectType
Definition: cppast.h:1549
CppVarDeclInList(CppTypeModifier modifier, CppVarDecl varDecl)
Definition: cppast.h:686
void addArraySize(CppExpr *arraySize)
Definition: cppast.h:540
void bitField(CppExpr *_bitField)
Definition: cppast.h:531
CppExpr * bitField()
Definition: cppast.h:527
AssignType assignType_
Definition: cppast.h:548
void name(std::string _name)
Definition: cppast.h:507
std::string & name()
Definition: cppast.h:503
void assign(CppExpr *assignVal, AssignType assignType)
Definition: cppast.h:520
CppExprPtr assignValue_
Definition: cppast.h:547
CppVarDecl(std::string name)
Definition: cppast.h:496
std::string name_
Definition: cppast.h:546
AssignType assignType()
Definition: cppast.h:516
CppArraySizes & arraySizes()
Definition: cppast.h:536
CppArraySizes arraySizes_
Definition: cppast.h:550
CppExprPtr bitField_
Definition: cppast.h:549
CppExpr * assignValue()
Definition: cppast.h:512
List of variables declared in a line without repeating its type, e.g.
Definition: cppast.h:699
CppVarList(CppVar *firstVar, CppVarDeclInList varDecl)
Definition: cppast.h:704
CppVarPtr firstVar_
Definition: cppast.h:702
CppVarDeclList & varDeclList()
Definition: cppast.h:718
CppVarDeclList varDeclList_
Definition: cppast.h:732
void accept(CppVisitorBase *v) override
Definition: cppast.h:723
static constexpr CppObjType kObjectType
Definition: cppast.h:700
CppVarPtr & firstVar()
Definition: cppast.h:714
void addVarDecl(CppVarDeclInList varDecl)
Definition: cppast.h:710
CppVarType(CppAccessType accessType, std::string baseType, std::uint32_t typeAttr, CppTypeModifier modifier)
Definition: cppast.h:476
CppTypeModifier typeModifier_
Definition: cppast.h:487
void typeAttr(std::uint32_t attr)
Definition: cppast.h:451
CppTypeModifier & typeModifier()
Definition: cppast.h:463
void baseType(std::string _baseType)
Definition: cppast.h:439
std::string & baseType()
Definition: cppast.h:435
bool paramPack_
Definition: cppast.h:426
std::string baseType_
Definition: cppast.h:485
void accept(CppVisitorBase *v) override
Definition: cppast.h:468
std::uint32_t typeAttr()
Definition: cppast.h:447
CppVarType(std::string baseType, CppTypeModifier modifier=CppTypeModifier())
Definition: cppast.h:2212
std::uint32_t typeAttr_
Definition: cppast.h:488
void addAttr(std::uint32_t attr)
Definition: cppast.h:455
CppObjPtr compound_
Definition: cppast.h:486
static constexpr CppObjType kObjectType
Definition: cppast.h:424
CppObj * compound()
Definition: cppast.h:443
Class to represent C++ variable definition.
Definition: cppast.h:565
std::uint32_t typeAttr()
Definition: cppast.h:603
CppArraySizes & arraySizes()
Definition: cppast.h:639
CppExpr * assignValue()
Definition: cppast.h:617
CppVarType * varType()
Definition: cppast.h:589
AssignType assignType()
Definition: cppast.h:621
CppTemplateParamList * templateParamList()
Definition: cppast.h:657
CppVarTypePtr varType_
Definition: cppast.h:675
std::string apidecor_
Definition: cppast.h:677
void accept(CppVisitorBase *v) override
Definition: cppast.h:666
void apidecor(std::string _apidecor)
Definition: cppast.h:652
void varType(CppVarTypePtr _varType)
Definition: cppast.h:593
CppVar(CppAccessType accessType, CppFunctionPointer *fptr, CppTypeModifier modifier)
Definition: cppast.h:582
void bitField(CppExpr *_bitField)
Definition: cppast.h:634
static constexpr CppObjType kObjectType
Definition: cppast.h:566
CppExpr * bitField()
Definition: cppast.h:630
void addAttr(std::uint32_t attr)
Definition: cppast.h:607
void assign(CppExpr *assignVal, AssignType assignType)
Definition: cppast.h:625
CppVarDecl & varDecl()
Definition: cppast.h:612
std::string & apidecor()
Definition: cppast.h:648
void templateParamList(CppTemplateParamList *templParamList)
Definition: cppast.h:661
CppTemplateParamListPtr templSpec_
Definition: cppast.h:678
CppVar(CppVarType *varType, CppVarDecl varDecl)
Definition: cppast.h:568
CppVarDecl varDecl_
Definition: cppast.h:676
CppVar(CppVarTypePtr varType, CppVarDecl varDecl)
Definition: cppast.h:575
std::string & name()
Definition: cppast.h:598
void addArraySize(CppExpr *arraySize)
Definition: cppast.h:643