CppParser
Loading...
Searching...
No Matches
cppwriter.cpp
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#include "cppwriter.h"
29
31
32namespace {
33static void emitAttribute(std::uint32_t attr, std::ostream& stm)
34{
35 if (attr & kStatic)
36 stm << "static ";
37 else if (attr & kExtern)
38 stm << "extern ";
39 else if (attr & kExternC)
40 stm << "extern C ";
41
42 if (attr & kConst)
43 stm << "const ";
44 if (attr & kConstExpr)
45 stm << "constexpr ";
46 if (attr & kVolatile)
47 stm << "volatile ";
48 if (attr & kMutable)
49 stm << "mutable ";
50}
51
52static void emitTypeModifier(CppTypeModifier& modifier, std::ostream& stm)
53{
54 std::uint8_t constBit = 0;
55 for (constBit = 0; constBit < modifier.ptrLevel_; ++constBit)
56 {
57 if (modifier.constBits_ & (1 << constBit))
58 stm << " const ";
59 stm << "*";
60 }
61 if (modifier.constBits_ & (1 << constBit))
62 stm << " const";
63 if (modifier.refType_ == CppRefType::kByRef)
64 stm << '&';
65 else if (modifier.refType_ == CppRefType::kRValRef)
66 stm << "&&";
67}
68} // namespace
69
70void CppWriter::emit(CppObj* cppObj, std::ostream& stm, CppIndent indentation) const
71{
72 return emit(cppObj, stm, indentation, false);
73}
74
75void CppWriter::emit(CppObj* cppObj, std::ostream& stm, CppIndent indentation, bool noNewLine) const
76{
77 switch (cppObj->objType_)
78 {
79 case CppObjType::kHashDefine:
80 return emitDefine((CppDefine*) cppObj, stm);
81 case CppObjType::kHashUndef:
82 return emitUndef((CppUndef*) cppObj, stm);
83 case CppObjType::kHashInclude:
84 return emitInclude((CppInclude*) cppObj, stm);
85 case CppObjType::kHashIf:
86 return emitHashIf((CppHashIf*) cppObj, stm);
87 case CppObjType::kHashPragma:
88 return emitPragma((CppPragma*) cppObj, stm);
89
90 case CppObjType::kVarType:
91 return emitVarType((CppVarType*) cppObj, stm);
92 case CppObjType::kVar: {
93 emitVar((CppVar*) cppObj, stm, indentation);
94 if (!noNewLine)
95 stm << ";\n";
96 return;
97 }
98 case CppObjType::kVarList:
99 return emitVarList((CppVarList*) cppObj, stm, indentation);
100 case CppObjType::kEnum:
101 return emitEnum((CppEnum*) cppObj, stm, !noNewLine, indentation);
102 case CppObjType::kDocComment:
103 return emitDocComment((CppDocComment*) cppObj, stm, indentation);
104 case CppObjType::kUsingDecl:
105 return emitUsingDecl((CppUsingDecl*) cppObj, stm, indentation);
106 case CppObjType::kTypedefName:
107 return emitTypedef((CppTypedefName*) cppObj, stm, indentation);
108 case CppObjType::kTypedefNameList:
109 return emitTypedefList((CppTypedefList*) cppObj, stm, indentation);
110 case CppObjType::kCompound:
111 return emitCompound((CppCompound*) cppObj, stm, indentation, !noNewLine);
112 case CppObjType::kFwdClsDecl:
113 return emitFwdDecl((CppFwdClsDecl*) cppObj, stm, indentation);
114 case CppObjType::kFunction:
115 return emitFunction((CppFunction*) cppObj, stm, !noNewLine, indentation);
116 case CppObjType::kConstructor:
117 return emitConstructor((CppConstructor*) cppObj, stm, indentation);
118 case CppObjType::kDestructor:
119 return emitDestructor((CppDestructor*) cppObj, stm, indentation);
120 case CppObjType::kTypeConverter:
121 return emitTypeConverter((CppTypeConverter*) cppObj, stm, indentation);
122 case CppObjType::kFunctionPtr:
123 return emitFunctionPtr((CppFunctionPointer*) cppObj, stm, !noNewLine, indentation);
124 case CppObjType::kIfBlock:
125 return emitIfBlock((CppIfBlock*) cppObj, stm, indentation);
126 case CppObjType::kWhileBlock:
127 return emitWhileBlock((CppWhileBlock*) cppObj, stm, indentation);
128 case CppObjType::kDoWhileBlock:
129 return emitDoBlock((CppDoWhileBlock*) cppObj, stm, indentation);
130 case CppObjType::kForBlock:
131 return emitForBlock((CppForBlock*) cppObj, stm, indentation);
132 case CppObjType::kExpression:
133 emitExpr((CppExpr*) cppObj, stm, indentation);
134 if (!noNewLine)
135 stm << ";\n";
136 break;
137 case CppObjType::kSwitchBlock:
138 return emitSwitchBlock(static_cast<CppSwitchBlock*>(cppObj), stm, indentation);
139 case CppObjType::kMacroCall:
140 return emitMacroCall(static_cast<CppMacroCall*>(cppObj), stm, indentation);
141
142 case CppObjType::kBlob:
143 return emitBlob((CppBlob*) cppObj, stm, true, indentation);
144
145 default:
146 break;
147 }
148}
149
150void CppWriter::emitDefine(CppDefine* defObj, std::ostream& stm) const
151{
152 stm << '#' << preproIndent_ << "define " << defObj->name_;
153 if (!defObj->defn_.empty())
154 {
155 const auto firstNonSpaceCharPos =
156 std::find_if(defObj->defn_.begin(), defObj->defn_.end(), [](char c) { return !std::isspace(c); });
157 if (firstNonSpaceCharPos != defObj->defn_.end())
158 {
159 if (*firstNonSpaceCharPos != '(')
160 stm << '\t';
161 stm << defObj->defn_;
162 }
163 }
164 stm << '\n';
165}
166
167void CppWriter::emitUndef(CppUndef* undefObj, std::ostream& stm) const
168{
169 stm << '#' << preproIndent_ << "undef " << undefObj->name_ << '\n';
170}
171
172void CppWriter::emitInclude(CppInclude* includeObj, std::ostream& stm) const
173{
174 stm << '#' << preproIndent_ << "include " << includeObj->name_ << '\n';
175}
176void CppWriter::emitHashIf(CppHashIf* hashIfObj, std::ostream& stm) const
177{
178 emitHashIf(hashIfObj->condType_, hashIfObj->cond_, stm);
179}
180
181void CppWriter::emitEndIf(std::ostream& stm) const
182{
183 stm << '#' << --preproIndent_ << "endif\n";
184}
185
186void CppWriter::emitHashIf(CppHashIf::CondType condType, const std::string& cond, std::ostream& stm) const
187{
188 switch (condType)
189 {
190 case CppHashIf::kIf:
191 stm << '#' << preproIndent_ << "if " << cond << '\n';
193 break;
194
196 stm << '#' << preproIndent_ << "ifdef " << cond << '\n';
198 break;
199
201 stm << '#' << preproIndent_ << "ifndef " << cond << '\n';
203 break;
204
205 case CppHashIf::kElIf:
206 stm << '#' << --preproIndent_ << "elif " << cond << '\n';
208 break;
209
210 case CppHashIf::kElse:
211 stm << '#' << --preproIndent_ << "else " << cond << '\n';
213 break;
214
216 emitEndIf(stm);
217 break;
218 }
219}
220
221void CppWriter::emitPragma(CppPragma* pragmaObj, std::ostream& stm) const
222{
223 stm << '#' << preproIndent_ << "pragma " << pragmaObj->defn_ << '\n';
224}
225
226void CppWriter::emitBlob(CppBlob* blobObj, std::ostream& stm, bool formatLineStarts, CppIndent indentation) const
227{
228 // if (formatLineStarts)
229 // {
230 // bool startOfLine = false;
231 // for (const auto ch : blobObj->blob_)
232 // {
233 // if (startOfLine)
234 // {
235 // if ((ch == ' ') || (ch == '\t'))
236 // continue;
237 // else if (ch != '\n')
238 // stm << indentation;
239 // }
240
241 // stm << ch;
242 // startOfLine = (ch == '\n');
243 // }
244 // }
245 // else
246 {
247 stm << blobObj->blob_;
248 }
249}
250
251void CppWriter::emitVarType(CppVarType* varTypeObj, std::ostream& stm) const
252{
253 const auto attr = varTypeObj->typeAttr() | (isConst(varTypeObj) ? CppIdentifierAttrib::kConst : 0);
254 emitAttribute(attr, stm);
255 if (varTypeObj->compound())
256 emit(varTypeObj->compound(), stm, CppIndent(), true);
257 else
258 stm << varTypeObj->baseType();
259 const auto& origTypeModifier = varTypeObj->typeModifier();
260 CppTypeModifier typeModifier {
261 origTypeModifier.refType_, origTypeModifier.ptrLevel_, origTypeModifier.constBits_ & ~1};
262 emitTypeModifier(typeModifier, stm);
263 if (varTypeObj->paramPack_)
264 stm << "...";
265}
266
267void CppWriter::emitVar(CppVar* varObj, std::ostream& stm, CppIndent indentation) const
268{
269 if (varObj->templateParamList())
270 emitTemplSpec(varObj->templateParamList(), stm, indentation);
271 emitVar(varObj, stm, indentation, false);
272}
273
274void CppWriter::emitVarDecl(std::ostream& stm, CppVarDecl& varDecl, bool skipName) const
275{
276 if (!skipName && !varDecl.name().empty())
277 stm << varDecl.name();
278 for (const auto& arrSize : varDecl.arraySizes())
279 {
280 stm << '[';
281 if (arrSize)
282 emitExpr(arrSize.get(), stm);
283 stm << ']';
284 }
285 if (varDecl.assignType() == AssignType::kUsingEqual)
286 {
287 stm << " = ";
288 emit(varDecl.assignValue(), stm, CppIndent(), true);
289 }
290 else if (varDecl.assignType() == AssignType::kUsingBracket)
291 {
292 stm << '(';
293 if (varDecl.assignValue())
294 emit(varDecl.assignValue(), stm, CppIndent(), true);
295 stm << ')';
296 }
297 else if (varDecl.assignType() == AssignType::kUsingBraces)
298 {
299 stm << '{';
300 if (varDecl.assignValue())
301 emit(varDecl.assignValue(), stm, CppIndent(), true);
302 stm << '}';
303 }
304}
305
306void CppWriter::emitVar(CppVar* varObj, std::ostream& stm, CppIndent indentation, bool skipName) const
307{
308 stm << indentation;
309 if (!varObj->apidecor().empty())
310 {
311 stm << varObj->apidecor() << ' ';
312 }
313 emitVarType(varObj->varType(), stm);
314 if (!skipName && !varObj->name().empty())
315 stm << ' ';
316 emitVarDecl(stm, varObj->varDecl(), skipName);
317}
318
319void CppWriter::emitVarList(CppVarList* varListObj, std::ostream& stm, CppIndent indentation /* = CppIndent()*/) const
320{
321 emitVar(varListObj->firstVar().get(), stm, indentation);
322 auto& varDeclList = varListObj->varDeclList();
323 for (size_t i = 0; i < varDeclList.size(); ++i)
324 {
325 stm << ", ";
326 auto& decl = varDeclList[i];
327 emitTypeModifier(decl, stm);
328 emitVarDecl(stm, decl, false);
329 }
330
331 stm << ";\n";
332}
333
334void CppWriter::emitEnum(CppEnum* enmObj, std::ostream& stm, bool emitNewLine, CppIndent indentation) const
335{
336 stm << indentation << "enum";
337 if (enmObj->isClass_)
338 stm << " class";
339 if (!enmObj->name_.empty())
340 stm << ' ' << enmObj->name_;
341 if (!enmObj->underlyingType_.empty())
342 stm << " : " << enmObj->underlyingType_;
343 if (enmObj->itemList_)
344 {
345 const bool isEnumBodyBlob = !enmObj->itemList_->empty() && enmObj->itemList_->front()->val_
346 && (enmObj->itemList_->front()->val_->objType_ == CppBlob::kObjectType);
347 if (isEnumBodyBlob)
348 {
349 stm << " {\n";
350 emitBlob((CppBlob*) enmObj->itemList_->front()->val_.get(), stm, false, indentation);
351 stm << '\n' << indentation << '}';
352 }
353 else
354 {
355 stm << '\n';
356 stm << indentation++.toString() << "{\n";
357 for (auto enmItem : *(enmObj->itemList_))
358 {
359 if (enmItem->name_.empty())
360 {
361 emit(enmItem->val_.get(), stm, indentation);
362 }
363 else
364 {
365 stm << indentation << enmItem->name_;
366 if (enmItem->val_ && isExpr(enmItem->val_.get()))
367 {
368 auto* expr = static_cast<CppExpr*>(enmItem->val_.get());
369 stm << " = ";
370 emitExpr(expr, stm);
371 }
372 if (enmItem != enmObj->itemList_->back())
373 stm << ",\n";
374 else
375 stm << '\n';
376 }
377 }
378 stm << --indentation << "}";
379 }
380 }
381 if (emitNewLine)
382 stm << ";\n";
383}
384
386 std::ostream& stm,
387 CppIndent indentation /* = CppIndent()*/) const
388{
389 stm << indentation << "typedef ";
390 emitVar(typedefName->var_.get(), stm);
391 stm << ";\n";
392}
393
395 std::ostream& stm,
396 CppIndent indentation /* = CppIndent()*/) const
397{
398 if (usingDecl->templateParamList())
399 emitTemplSpec(usingDecl->templateParamList(), stm, indentation);
400 stm << indentation << "using " << usingDecl->name_;
401 if (usingDecl->cppObj_)
402 {
403 stm << " = ";
404 emit(usingDecl->cppObj_.get(), stm);
405 }
406 stm << ";\n";
407}
408
410 std::ostream& stm,
411 CppIndent indentation /* = CppIndent()*/) const
412{
413 stm << indentation << "typedef ";
414 emitVarList(typedefList->varList_.get(), stm);
415}
416
418 std::ostream& stm,
419 CppIndent indentation /* = CppIndent()*/) const
420{
421 if (fwdDeclObj->templateParamList())
422 emitTemplSpec(fwdDeclObj->templateParamList(), stm, indentation);
423 stm << indentation;
424 if (fwdDeclObj->attr() & kFriend)
425 stm << "friend ";
426 if (fwdDeclObj->cmpType_ != CppCompoundType::kUnknownCompound)
427 stm << fwdDeclObj->cmpType_ << ' ';
428 if (!fwdDeclObj->apidecor_.empty())
429 stm << fwdDeclObj->apidecor_ << ' ';
430 stm << fwdDeclObj->name_ << ";\n";
431}
432
434 std::ostream& stm,
435 CppIndent indentation /* = CppIndent()*/) const
436{
437 stm << indentation << macroCallObj->macroCall_ << '\n';
438}
439
440void CppWriter::emitTemplSpec(CppTemplateParamList* templSpec, std::ostream& stm, CppIndent indentation) const
441{
442 stm << indentation << "template <";
443 if (templSpec)
444 {
445 const char* sep = "";
446 for (auto& param : *templSpec)
447 {
448 stm << sep;
449 if (param->paramType_)
450 {
451 if (param->paramType_->objType_ == CppVarType::kObjectType)
452 emitVarType(static_cast<CppVarType*>(param->paramType_.get()), stm);
453 else
454 emitFunctionPtr(static_cast<CppFunctionPointer*>(param->paramType_.get()), stm, false);
455 stm << ' ';
456 }
457 else
458 {
459 stm << "typename ";
460 }
461 stm << param->paramName_;
462 if (param->defaultArg())
463 {
464 stm << " = ";
465 emit(param->defaultArg(), stm, CppIndent(), true);
466 }
467 sep = ", ";
468 }
469 }
470 stm << ">\n";
471}
472
473void CppWriter::emitCompound(CppCompound* compoundObj, std::ostream& stm, CppIndent indentation, bool emitNewLine) const
474{
475 if (isNamespaceLike(compoundObj))
476 {
477 if (compoundObj->templateParamList())
478 {
479 emitTemplSpec(compoundObj->templateParamList(), stm, indentation);
480 }
481 stm << indentation << compoundObj->compoundType() << ' ';
482 if (!compoundObj->apidecor().empty())
483 stm << compoundObj->apidecor() << ' ';
484 stm << compoundObj->name();
485 if (compoundObj->hasAttr(kFinal))
486 stm << " final";
487 }
488 if (compoundObj->inheritanceList())
489 {
490 ++indentation;
491 char sep = ':';
492 stm << ' ';
493 for (CppInheritanceList::const_iterator inhItr = compoundObj->inheritanceList()->begin();
494 inhItr != compoundObj->inheritanceList()->end();
495 ++inhItr)
496 {
497 stm << sep << ' ' << inhItr->inhType << ' ' << inhItr->baseName;
498 sep = ',';
499 }
500 --indentation;
501 }
502 if (isNamespaceLike(compoundObj) || compoundObj->compoundType() == CppCompoundType::kUnknownCompound)
503 stm << '\n' << indentation++.toString() << "{\n";
504 else if (compoundObj->compoundType() == CppCompoundType::kExternCBlock)
505 stm << indentation++.toString() << "extern \"C\" {\n";
506
507 CppAccessType lastAccessType = CppAccessType::kUnknown;
508 forEachMember(compoundObj, [&](CppObj* memObj) {
509 if (isClassLike(compoundObj) && memObj->accessType_ != CppAccessType::kUnknown
510 && lastAccessType != memObj->accessType_)
511 {
512 stm << --indentation << memObj->accessType_ << ':' << '\n';
513 lastAccessType = memObj->accessType_;
514 ++indentation;
515 }
516 emit(memObj, stm, indentation);
517 if (memObj->objType_ == CppBlob::kObjectType)
518 stm << '\n';
519
520 return false;
521 });
522
523 if (isNamespaceLike(compoundObj)|| compoundObj->compoundType() == CppCompoundType::kUnknownCompound)
524 {
525 stm << --indentation;
526 stm << '}';
527 if (emitNewLine)
528 {
529 if (isClassLike(compoundObj))
530 stm << ';';
531 stm << '\n';
532 }
533 }
534 else if (compoundObj->compoundType() == CppCompoundType::kExternCBlock)
535 stm << indentation << "}\n";
536}
537
538void CppWriter::emitParamList(CppParamVector* paramListObj, std::ostream& stm) const
539{
540 emitParamList(paramListObj, stm, false);
541}
542
543void CppWriter::emitParamList(CppParamVector* paramListObj, std::ostream& stm, bool skipParamName) const
544{
545 for (auto prmItr = paramListObj->begin(); prmItr != paramListObj->end(); ++prmItr)
546 {
547 if (prmItr != paramListObj->begin())
548 stm << ", ";
549 auto& param = *prmItr;
550 switch (param->objType_)
551 {
552 case CppObjType::kVar:
553 emitVar(static_cast<CppVar*>(param.get()), stm, CppIndent(), skipParamName);
554 break;
555 case CppObjType::kFunctionPtr:
556 emitFunctionPtr(static_cast<CppFunctionPointer*>(param.get()), stm, skipParamName);
557 break;
558 default:
559 assert(false);
560 }
561 }
562}
563
565 std::ostream& stm,
566 CppIndent indentation,
567 bool skipName,
568 bool skipParamName,
569 bool emitNewLine) const
570{
571 if (funcObj->templateParamList())
572 emitTemplSpec(funcObj->templateParamList(), stm, indentation);
573
574 if ((funcObj->attr() & (kFuncParam | kTypedef)) == 0)
575 stm << indentation;
576 if (!funcObj->decor1().empty())
577 stm << funcObj->decor1() << ' ';
578 if (funcObj->hasAttr(kStatic))
579 stm << "static ";
580 else if (funcObj->hasAttr(kExtern))
581 stm << "extern ";
582 else if (funcObj->hasAttr(kVirtual) && !(funcObj->hasAttr(kOverride) || funcObj->hasAttr(kFinal)))
583 stm << "virtual ";
584 else if (funcObj->hasAttr(kInline))
585 stm << "inline ";
586 else if (funcObj->hasAttr(kExplicit))
587 stm << "explicit ";
588 else if (funcObj->hasAttr(kFriend))
589 stm << "friend ";
590 if (funcObj->hasAttr(kConstExpr))
591 stm << "constexpr ";
592 if (funcObj->hasAttr(kTrailingRet))
593 stm << "auto";
594 else
595 emitVarType(funcObj->retType_.get(), stm);
596 if (funcObj->objType_ == CppObjType::kFunctionPtr)
597 stm << " (";
598 else
599 stm << ' ';
600 if (!funcObj->decor2().empty())
601 stm << funcObj->decor2() << ' ';
602 if (funcObj->objType_ == CppObjType::kFunctionPtr)
603 {
604 stm << '*';
605 if (!skipName)
606 stm << funcObj->name_ << ") ";
607 }
608 else if (!skipName)
609 {
610 stm << funcObj->name_;
611 }
612 stm << '(';
613 if (funcObj->params())
614 emitParamList(funcObj->params(), stm, skipParamName);
615 stm << ')';
616
617 if ((funcObj->attr() & kConst) == kConst)
618 stm << " const";
619 if ((funcObj->attr() & kPureVirtual) == kPureVirtual)
620 stm << " = 0";
621 else if ((funcObj->attr() & kOverride) == kOverride)
622 stm << " override";
623 else if ((funcObj->attr() & kFinal) == kFinal)
624 stm << " final";
625
626 if (funcObj->attr() & kTrailingRet)
627 {
628 stm << " -> ";
629 emitVarType(funcObj->retType_.get(), stm);
630 }
631 if (!skipParamName && funcObj->defn() && (getEmittingType() != kHeader))
632 {
633 const auto defn = funcObj->defn();
634 if (defn->hasASingleBlobMember())
635 {
636 stm << '\n' << indentation++.toString() << "{\n";
637 emitBlob((CppBlob*) defn->members().front().get(), stm, false, indentation);
638 stm << '\n' << --indentation << "}\n";
639 }
640 else
641 {
642 stm << '\n' << indentation++.toString() << "{\n";
643 emitCompound(funcObj->defn(), stm, indentation);
644 stm << --indentation << "}\n";
645 }
646 }
647 else if (emitNewLine && ((funcObj->attr() & kFuncParam) == 0))
648 {
649 stm << ";\n";
650 }
651}
652
653void CppWriter::emitFunction(CppFunction* funcObj, std::ostream& stm, bool emitNewLine, CppIndent indentation) const
654{
655 return emitFunction(funcObj, stm, indentation, false, false, emitNewLine);
656}
657
659 std::ostream& stm,
660 bool emitNewLine,
661 CppIndent indentation) const
662{
663 if (funcPtrObj->attr() & kTypedef)
664 stm << indentation << "typedef ";
665 emitFunction((CppFunction*) funcPtrObj, stm, emitNewLine, indentation);
666}
667
669 std::ostream& stm,
670 CppIndent indentation,
671 bool skipParamName) const
672{
673 if (ctorObj->templateParamList())
674 {
675 emitTemplSpec(ctorObj->templateParamList(), stm, indentation);
676 }
677 stm << indentation;
678 if (!ctorObj->decor1().empty())
679 stm << ctorObj->decor1() << ' ';
680 if (ctorObj->attr() & kInline)
681 stm << "inline ";
682 else if (ctorObj->attr() & kExplicit)
683 stm << "explicit ";
684 stm << ctorObj->name_;
685 stm << '(';
686 if (ctorObj->params())
687 emitParamList(ctorObj->params(), stm, skipParamName);
688 stm << ')';
689 if (!skipParamName && ctorObj->memInits_.memInitList)
690 {
691 char sep = ':';
692 ++indentation;
693 if (ctorObj->memInits_.memInitListIsABlob_)
694 {
695 stm << '\n';
696 stm << indentation << sep << ' ';
697 emitBlob(ctorObj->memInits_.blob, stm, true, indentation.resetted());
698 }
699 else
700 {
701 for (const auto& memInit : *(ctorObj->memInits_.memInitList))
702 {
703 stm << '\n';
704 stm << indentation << sep << ' ' << memInit.first << '(';
705 emitExpr(memInit.second, stm);
706 stm << ')';
707 sep = ',';
708 }
709 }
710 --indentation;
711 }
712 if (!skipParamName && ctorObj->defn())
713 {
714 stm << '\n' << indentation++.toString() << "{\n";
715 emitCompound(ctorObj->defn(), stm, indentation);
716 stm << --indentation << "}\n";
717 }
718 else
719 {
720 if (isDeleted(ctorObj))
721 stm << " = delete";
722 stm << ";\n";
723 }
724}
725
726void CppWriter::emitConstructor(CppConstructor* ctorObj, std::ostream& stm, CppIndent indentation) const
727{
728 emitConstructor(ctorObj, stm, indentation, false);
729}
730
732 std::ostream& stm,
733 CppIndent indentation /* = CppIndent()*/) const
734{
735 if (dtorObj->templateParamList())
736 emitTemplSpec(dtorObj->templateParamList(), stm, indentation);
737 stm << indentation;
738 if (!dtorObj->decor1().empty())
739 stm << dtorObj->decor1() << ' ';
740 if (dtorObj->attr() & kInline)
741 stm << "inline ";
742 else if (dtorObj->attr() & kExplicit)
743 stm << "explicit ";
744 else if (dtorObj->attr() & kVirtual)
745 stm << "virtual ";
746 stm << dtorObj->name_ << "()";
747
748 if (dtorObj->defn())
749 {
750 stm << '\n' << indentation++.toString() << "{\n";
751 emitCompound(dtorObj->defn(), stm, indentation);
752 stm << --indentation << "}\n";
753 }
754 else
755 {
756 stm << ";\n";
757 }
758}
759
760void CppWriter::emitTypeConverter(CppTypeConverter* typeConverterObj, std::ostream& stm, CppIndent indentation) const
761{
762 if (typeConverterObj->templateParamList())
763 emitTemplSpec(typeConverterObj->templateParamList(), stm, indentation);
764 stm << indentation << "operator ";
765 emitVarType(typeConverterObj->to_.get(), stm);
766 stm << "()";
767 if (typeConverterObj->attr() & kConst)
768 stm << " const";
769 if (typeConverterObj->attr() & kConstExpr)
770 stm << " constexpr";
771 if (typeConverterObj->defn())
772 {
773 stm << '\n';
774 stm << indentation << "{\n";
775 ++indentation;
776 emitCompound(typeConverterObj->defn(), stm, indentation);
777 --indentation;
778 stm << indentation << "}\n";
779 }
780 else
781 {
782 stm << ";\n";
783 }
784}
785
787 std::ostream& stm,
788 CppIndent indentation /* = CppIndent()*/) const
789{
790 stm << docCommentObj->doc_ << '\n';
791}
792
793inline void emitOperator(std::ostream& stm, CppOperator op)
794{
795 switch (op)
796 {
797 case kUnaryMinus:
798 stm << '-';
799 break;
800 case kBitToggle:
801 stm << '~';
802 break;
803 case kLogNot:
804 stm << '!';
805 break;
806 case kDerefer:
807 stm << '*';
808 break;
809 case kRefer:
810 stm << '&';
811 break;
812 case kPreIncrement:
813 case kPostIncrement:
814 stm << "++";
815 break;
816 case kPreDecrement:
817 case kPostDecrement:
818 stm << "--";
819 break;
820 case kPlus:
821 stm << '+';
822 break;
823 case kMinus:
824 stm << '-';
825 break;
826 case kMul:
827 stm << '*';
828 break;
829 case kDiv:
830 stm << '/';
831 break;
832 case kPercent:
833 stm << '%';
834 break;
835 case kAnd:
836 stm << "&&";
837 break;
838 case kOr:
839 stm << "||";
840 break;
841 case kBitAnd:
842 stm << '&';
843 break;
844 case kBitOr:
845 stm << '|';
846 break;
847 case kXor:
848 stm << '^';
849 break;
850 case kEqual:
851 stm << '=';
852 break;
853 case kLess:
854 stm << '<';
855 break;
856 case kGreater:
857 stm << '>';
858 break;
859 case kPlusEqual:
860 stm << "+=";
861 break;
862 case kMinusEqual:
863 stm << "-=";
864 break;
865 case kMulEqual:
866 stm << "*=";
867 break;
868 case kDivEqual:
869 stm << "/=";
870 break;
871 case kPerEqual:
872 stm << "%=";
873 break;
874 case kXorEqual:
875 stm << "^=";
876 break;
877 case kAndEqual:
878 stm << "&=";
879 break;
880 case kOrEqual:
881 stm << "|=";
882 break;
883 case kLeftShift:
884 stm << "<<";
885 break;
886 case kRightShift:
887 stm << ">>";
888 break;
889 case kLShiftEqual:
890 stm << "<<=";
891 break;
892 case kRShiftEqual:
893 stm << ">>=";
894 break;
895 case kCmpEqual:
896 stm << "==";
897 break;
898 case kNotEqual:
899 stm << "!=";
900 break;
901 case kLessEqual:
902 stm << "<=";
903 break;
904 case kGreaterEqual:
905 stm << ">=";
906 break;
907 case k3WayCmp:
908 stm << "<=>";
909 break;
910 case kComma:
911 stm << ',';
912 break;
913 case kDot:
914 stm << '.';
915 break;
916 case kArrow:
917 stm << "->";
918 break;
919 case kArrowStar:
920 stm << "->*";
921 break;
922
923 default:
924 break;
925 }
926}
927
928void CppWriter::emitExprAtom(CppExprAtom& exprAtm, std::ostream& stm, CppIndent indentation /*= CppIndent()*/) const
929{
930 switch (exprAtm.type)
931 {
932 case CppExprAtom::kAtom:
933 stm << *(exprAtm.atom);
934 break;
935 case CppExprAtom::kExpr:
936 emitExpr(exprAtm.expr, stm);
937 break;
938 case CppExprAtom::kVarType:
939 emitVarType(exprAtm.varType, stm);
940
941 default:
942 break;
943 }
944}
945
946void CppWriter::emitExpr(CppExpr* exprObj, std::ostream& stm, CppIndent indentation /*= CppIndent()*/) const
947{
948 if (exprObj == NULL)
949 return;
950 stm << indentation;
951 if (exprObj->flags_ & CppExpr::kReturn)
952 stm << "return ";
953 if (exprObj->flags_ & CppExpr::kThrow)
954 stm << "throw ";
955 if (exprObj->flags_ & CppExpr::kInitializer)
956 stm << "{";
957 if (exprObj->flags_ & CppExpr::kBracketed)
958 stm << '(';
959 if (exprObj->flags_ & CppExpr::kNew)
960 stm << "new ";
961 if (exprObj->flags_ & CppExpr::kSizeOf)
962 stm << "sizeof(";
963 else if (exprObj->flags_ & CppExpr::kDelete)
964 stm << "delete ";
965 else if (exprObj->flags_ & CppExpr::kDeleteArray)
966 stm << "delete[] ";
967 if (exprObj->oper_ == kNone)
968 {
969 emitExprAtom(exprObj->expr1_, stm);
970 }
971 else if (exprObj->oper_ > kUnariPrefixOperatorStart && exprObj->oper_ < kUnariSufixOperatorStart)
972 {
973 emitOperator(stm, exprObj->oper_);
974 emitExprAtom(exprObj->expr1_, stm);
975 }
976 else if (exprObj->oper_ > kUnariSufixOperatorStart && exprObj->oper_ < kBinaryOperatorStart)
977 {
978 emitExprAtom(exprObj->expr1_, stm);
979 emitOperator(stm, exprObj->oper_);
980 }
981 else if (exprObj->oper_ > kBinaryOperatorStart && exprObj->oper_ < kDerefOperatorStart)
982 {
983 emitExprAtom(exprObj->expr1_, stm);
984 if (exprObj->oper_ != kComma)
985 stm << ' ';
986 emitOperator(stm, exprObj->oper_);
987 stm << ' ';
988 emitExprAtom(exprObj->expr2_, stm);
989 }
990 else if (exprObj->oper_ > kDerefOperatorStart && exprObj->oper_ < kSpecialOperations)
991 {
992 emitExprAtom(exprObj->expr1_, stm);
993 emitOperator(stm, exprObj->oper_);
994 emitExprAtom(exprObj->expr2_, stm);
995 }
996 else if (exprObj->oper_ == kFunctionCall)
997 {
998 emitExprAtom(exprObj->expr1_, stm);
999 stm << '(';
1000 emitExprAtom(exprObj->expr2_, stm);
1001 stm << ')';
1002 }
1003 else if (exprObj->oper_ == kUniformInitCall)
1004 {
1005 emitExprAtom(exprObj->expr1_, stm);
1006 stm << '{';
1007 emitExprAtom(exprObj->expr2_, stm);
1008 stm << '}';
1009 }
1010 else if (exprObj->oper_ == kArrayElem)
1011 {
1012 emitExprAtom(exprObj->expr1_, stm);
1013 stm << '[';
1014 emitExprAtom(exprObj->expr2_, stm);
1015 stm << ']';
1016 }
1017 else if (exprObj->oper_ == kCStyleCast)
1018 {
1019 stm << '(';
1020 emitExprAtom(exprObj->expr1_, stm);
1021 stm << ") ";
1022 emitExprAtom(exprObj->expr2_, stm);
1023 }
1024 else if (exprObj->oper_ >= kConstCast && exprObj->oper_ <= kReinterpretCast)
1025 {
1026 if (exprObj->oper_ == kConstCast)
1027 stm << "const_cast";
1028 else if (exprObj->oper_ == kStaticCast)
1029 stm << "static_cast";
1030 else if (exprObj->oper_ == kDynamicCast)
1031 stm << "dynamic_cast";
1032 else if (exprObj->oper_ == kReinterpretCast)
1033 stm << "reinterpret_cast";
1034 stm << '<';
1035 emitExprAtom(exprObj->expr1_, stm);
1036 stm << ">(";
1037 emitExprAtom(exprObj->expr2_, stm);
1038 stm << ')';
1039 }
1040 else if (exprObj->oper_ == kTertiaryOperator)
1041 {
1042 emitExprAtom(exprObj->expr1_, stm);
1043 stm << " ? ";
1044 emitExprAtom(exprObj->expr2_, stm);
1045 stm << " : ";
1046 emitExprAtom(exprObj->expr3_, stm);
1047 }
1048 else if (exprObj->oper_ == kPlacementNew)
1049 {
1050 stm << "new (";
1051 emitExprAtom(exprObj->expr1_, stm);
1052 stm << ") ";
1053 emitExprAtom(exprObj->expr2_, stm);
1054 }
1055
1056 if (exprObj->flags_ & CppExpr::kBracketed)
1057 stm << ')';
1058 if (exprObj->flags_ & CppExpr::kInitializer)
1059 stm << "}";
1060 if (exprObj->flags_ & CppExpr::kSizeOf)
1061 stm << ')';
1062
1063 if (exprObj->flags_ & CppExpr::kVariadicPack)
1064 stm << "...";
1065}
1066
1067void CppWriter::emitIfBlock(CppIfBlock* ifBlock, std::ostream& stm, CppIndent indentation) const
1068{
1069 stm << indentation;
1070 stm << "if (";
1071 emit(ifBlock->cond_.get(), stm, CppIndent(), true);
1072 stm << ")\n";
1073 stm << indentation << "{\n";
1074 ++indentation;
1075 if (ifBlock->body_)
1076 emit(ifBlock->body_.get(), stm, indentation);
1077 --indentation;
1078 stm << indentation << "}\n";
1079 if (ifBlock->elsePart())
1080 {
1081 stm << indentation << "else \n";
1082 stm << indentation << "{\n";
1083 ++indentation;
1084 emit(ifBlock->elsePart(), stm, indentation);
1085 --indentation;
1086 stm << indentation << "}\n";
1087 }
1088}
1089
1090void CppWriter::emitWhileBlock(CppWhileBlock* whileBlock, std::ostream& stm, CppIndent indentation) const
1091{
1092 stm << indentation;
1093 stm << "while (";
1094 emit(whileBlock->cond_.get(), stm, CppIndent(), true);
1095 stm << ")\n";
1096 stm << indentation << "{\n";
1097 ++indentation;
1098 if (whileBlock->body_)
1099 emit(whileBlock->body_.get(), stm, indentation);
1100 --indentation;
1101 stm << indentation << "}\n";
1102}
1103
1104void CppWriter::emitDoBlock(CppDoWhileBlock* doBlock, std::ostream& stm, CppIndent indentation) const
1105{
1106 stm << indentation << "do\n";
1107 stm << indentation << "{\n";
1108 ++indentation;
1109 if (doBlock->body_)
1110 emit(doBlock->body_.get(), stm, indentation);
1111 --indentation;
1112 stm << indentation << "} while (";
1113 emit(doBlock->cond_.get(), stm, CppIndent(), true);
1114 stm << ");\n";
1115}
1116
1117void CppWriter::emitForBlock(CppForBlock* forBlock, std::ostream& stm, CppIndent indentation) const
1118{
1119 stm << indentation << "for (";
1120 if (forBlock->start_.get())
1121 emit(forBlock->start_.get(), stm, CppIndent(), true);
1122 stm << ';';
1123 if (forBlock->stop_)
1124 {
1125 stm << ' ';
1126 emitExpr(forBlock->stop_.get(), stm);
1127 }
1128 stm << ';';
1129 if (forBlock->step_)
1130 {
1131 stm << ' ';
1132 emitExpr(forBlock->step_.get(), stm);
1133 }
1134 stm << ")\n";
1135 stm << indentation << "{\n";
1136 ++indentation;
1137 if (forBlock->body_)
1138 emit(forBlock->body_.get(), stm, indentation);
1139 --indentation;
1140 stm << indentation << "}\n";
1141}
1142
1143void CppWriter::emitSwitchBlock(CppSwitchBlock* switchBlock, std::ostream& stm, CppIndent indentation) const
1144{
1145 stm << indentation << "switch(";
1146 emitExpr(switchBlock->cond_.get(), stm);
1147 stm << ")\n";
1148 stm << indentation++.toString() << "{\n";
1149 for (const auto& caseStmt : *(switchBlock->body_))
1150 {
1151 if (caseStmt.case_)
1152 {
1153 stm << indentation++.toString() << "case ";
1154 emitExpr(caseStmt.case_.get(), stm);
1155 stm << ":\n";
1156 }
1157 else
1158 {
1159 stm << "default:\n";
1160 }
1161 if (caseStmt.body_)
1162 emitCompound(caseStmt.body_.get(), stm, indentation);
1163 --indentation;
1164 }
1165 stm << --indentation << "}\n";
1166}
Helper class to manage indentation while writing C++ file from AST.
Definition: cppindent.h:33
std::string toString() const
Definition: cppindent.h:90
CppIndent resetted() const
Definition: cppindent.h:108
virtual void emitMacroCall(CppMacroCall *macroCallObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:433
virtual void emitEnum(CppEnum *enmObj, std::ostream &stm, bool emitNewLine, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:334
virtual void emitFwdDecl(CppFwdClsDecl *fwdClsDeclObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:417
CppIndent preproIndent_
Definition: cppwriter.h:158
virtual void emitVarType(CppVarType *varTypeObj, std::ostream &stm) const
Definition: cppwriter.cpp:251
virtual void emitHashIf(CppHashIf *hashIfObj, std::ostream &stm) const
Definition: cppwriter.cpp:176
virtual void emitIfBlock(CppIfBlock *ifBlock, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:1067
virtual void emitParamList(CppParamVector *paramListObj, std::ostream &stm) const
Definition: cppwriter.cpp:538
virtual void emitUsingDecl(CppUsingDecl *usingDecl, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:394
@ kHeader
No function definition is emitted unless it is explicitly inline.
Definition: cppwriter.h:47
virtual void emitEndIf(std::ostream &stm) const
Definition: cppwriter.cpp:181
virtual void emitConstructor(CppConstructor *ctorObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:726
EmittingType getEmittingType() const
Definition: cppwriter.h:173
void emitVarDecl(std::ostream &stm, CppVarDecl &varDecl, bool skipName) const
Definition: cppwriter.cpp:274
virtual void emitExpr(CppExpr *exprObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:946
virtual void emitDoBlock(CppDoWhileBlock *doBlock, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:1104
virtual void emitSwitchBlock(CppSwitchBlock *switchBlock, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:1143
virtual void emitInclude(CppInclude *includeObj, std::ostream &stm) const
Definition: cppwriter.cpp:172
virtual void emitTypeConverter(CppTypeConverter *typeConverterObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:760
virtual void emitDestructor(CppDestructor *dtorObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:731
void emitTemplSpec(CppTemplateParamList *templSpec, std::ostream &stm, CppIndent indentation) const
Definition: cppwriter.cpp:440
virtual void emitTypedefList(CppTypedefList *typedefList, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:409
virtual void emitDefine(CppDefine *defineObj, std::ostream &stm) const
Definition: cppwriter.cpp:150
virtual void emitBlob(CppBlob *blobObj, std::ostream &stm, bool formatLineStarts, CppIndent indentation) const
Definition: cppwriter.cpp:226
virtual void emitDocComment(CppDocComment *docCommentObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:786
virtual void emitTypedef(CppTypedefName *typedefName, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:385
virtual void emitCompound(CppCompound *compoundObj, std::ostream &stm, CppIndent indentation=CppIndent(), bool emitNewLine=true) const
Definition: cppwriter.cpp:473
virtual void emitFunctionPtr(CppFunctionPointer *funcPtrObj, std::ostream &stm, bool emitNewLine, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:658
virtual void emitVarList(CppVarList *varListObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:319
virtual void emitPragma(CppPragma *pragmaObj, std::ostream &stm) const
Definition: cppwriter.cpp:221
virtual void emitUndef(CppUndef *undefObj, std::ostream &stm) const
Definition: cppwriter.cpp:167
virtual void emitForBlock(CppForBlock *forBlock, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:1117
virtual void emitVar(CppVar *varObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:267
virtual void emitWhileBlock(CppWhileBlock *whileBlock, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:1090
virtual void emit(CppObj *cppObj, std::ostream &stm, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:70
virtual void emitFunction(CppFunction *funcObj, std::ostream &stm, bool emitNewLine, CppIndent indentation=CppIndent()) const
Definition: cppwriter.cpp:653
std::vector< std::unique_ptr< CppTemplateParam > > CppTemplateParamList
Definition: cppast.h:556
bool forEachMember(CppCompoundEPtr compound, std::function< bool(CppObj *)> visitor)
CppAccessType
Definition: cppconst.h:103
@ kTypedef
Definition: cppconst.h:198
@ kStatic
Definition: cppconst.h:190
@ kTrailingRet
Definition: cppconst.h:206
@ kConst
Definition: cppconst.h:189
@ kExtern
Definition: cppconst.h:191
@ kFinal
Definition: cppconst.h:201
@ kVirtual
Definition: cppconst.h:193
@ kExplicit
Definition: cppconst.h:196
@ kVolatile
Definition: cppconst.h:200
@ kInline
Definition: cppconst.h:192
@ kFriend
Definition: cppconst.h:197
@ kFuncParam
Definition: cppconst.h:188
@ kConstExpr
Definition: cppconst.h:199
@ kMutable
Definition: cppconst.h:207
@ kPureVirtual
Definition: cppconst.h:194
@ kExternC
Definition: cppconst.h:205
@ kOverride
Definition: cppconst.h:195
CppOperator
Definition: cppconst.h:111
@ kGreater
Definition: cppconst.h:140
@ kRefer
Definition: cppconst.h:119
@ kBitOr
Definition: cppconst.h:136
@ kPostIncrement
Definition: cppconst.h:124
@ kDerefer
Definition: cppconst.h:118
@ kLess
Definition: cppconst.h:139
@ kBitAnd
Definition: cppconst.h:135
@ kUnaryMinus
Definition: cppconst.h:115
@ kAnd
Definition: cppconst.h:133
@ kBitToggle
Definition: cppconst.h:116
@ kPercent
Definition: cppconst.h:132
@ kEqual
Definition: cppconst.h:138
@ kLogNot
Definition: cppconst.h:117
@ kPreIncrement
Definition: cppconst.h:120
@ kOr
Definition: cppconst.h:134
@ kMinus
Definition: cppconst.h:129
@ kXor
Definition: cppconst.h:137
@ kPostDecrement
Definition: cppconst.h:125
@ kMul
Definition: cppconst.h:130
@ kPlus
Definition: cppconst.h:128
@ kDiv
Definition: cppconst.h:131
@ kPreDecrement
Definition: cppconst.h:121
bool isDeleted(CppFunctionBase *func)
bool isConst(CppFunctionBase *func)
bool isClassLike(CppObj *cppObj)
bool isExpr(CppObj *cppObj)
bool isNamespaceLike(CppObj *cppObj)
std::vector< CppObjPtr > CppParamVector
Definition: cpptoken.h:110
void emitOperator(std::ostream &stm, CppOperator op)
Definition: cppwriter.cpp:793
static void emitAttribute(std::uint32_t attr, std::ostream &stm)
Definition: cppwriter.cpp:33
static void emitTypeModifier(CppTypeModifier &modifier, std::ostream &stm)
Definition: cppwriter.cpp:52
A stream of text that represents some content in a C++ program.
Definition: cppast.h:167
std::string blob_
Definition: cppast.h:169
static constexpr CppObjType kObjectType
Definition: cppast.h:168
Some blocks have common structure like if, while, and do-while.
Definition: cppast.h:1923
All classes, structs, unions, and namespaces can be classified as a Compound object.
Definition: cppast.h:927
CppTemplateParamList * templateParamList()
Definition: cppast.h:996
bool hasAttr(std::uint32_t _attr)
Definition: cppast.h:1095
std::string & name()
Definition: cppast.h:953
std::string & apidecor()
Definition: cppast.h:987
CppCompoundType compoundType()
Definition: cppast.h:969
CppInheritanceListPtr & inheritanceList()
Definition: cppast.h:1009
CppMemInits memInits_
Definition: cppast.h:1466
std::string defn_
This will contain everything after name.
Definition: cppast.h:194
std::string name_
Definition: cppast.h:193
std::string doc_
Entire comment text.
Definition: cppast.h:1650
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
An expression in a C/C++ program.
Definition: cppast.h:1750
CppParamVector * params()
Definition: cppast.h:1263
CppCompound * defn()
Definition: cppast.h:1171
bool hasAttr(std::uint32_t _attr)
Definition: cppast.h:1206
std::string & decor1()
Definition: cppast.h:1211
CppTemplateParamList * templateParamList()
Definition: cppast.h:1229
std::string name_
Definition: cppast.h:1196
std::string & decor2()
Definition: cppast.h:1220
std::uint32_t attr()
Definition: cppast.h:1198
Function pointer type definition using typedef, e.g.
Definition: cppast.h:1390
CppVarTypePtr retType_
Definition: cppast.h:1290
CppCompoundType cmpType_
Definition: cppast.h:861
std::uint32_t attr()
Definition: cppast.h:882
std::string name_
Definition: cppast.h:862
CppTemplateParamList * templateParamList()
Definition: cppast.h:891
std::string apidecor_
Definition: cppast.h:863
Represents all variants of #if preprocessors.
Definition: cppast.h:276
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
std::string name_
Definition: cppast.h:236
std::string macroCall_
Definition: cppast.h:786
bool memInitListIsABlob_
Definition: cppast.h:1432
std::list< CppMemInit > * memInitList
Definition: cppast.h:1435
CppBlob * blob
Definition: cppast.h:1436
An abstract class that is used as base class of all other classes.
Definition: cppast.h:134
CppAccessType accessType_
All objects do not need this.
Definition: cppast.h:136
CppObjType objType_
Definition: cppast.h:135
std::string defn_
Definition: cppast.h:311
CppVarTypePtr to_
Definition: cppast.h:1529
std::uint8_t ptrLevel_
Definition: typemodifier.h:31
CppRefType refType_
Definition: typemodifier.h:30
std::uint32_t constBits_
Definition: typemodifier.h:47
CppVarListPtr varList_
Definition: cppast.h:764
CppVarPtr var_
Definition: cppast.h:739
std::string name_
Definition: cppast.h:216
CppObjPtr cppObj_
Definition: cppast.h:1572
std::string name_
Definition: cppast.h:1571
CppTemplateParamList * templateParamList()
Definition: cppast.h:1601
std::string & name()
Definition: cppast.h:503
AssignType assignType()
Definition: cppast.h:516
CppArraySizes & arraySizes()
Definition: cppast.h:536
CppExpr * assignValue()
Definition: cppast.h:512
List of variables declared in a line without repeating its type, e.g.
Definition: cppast.h:699
CppVarDeclList & varDeclList()
Definition: cppast.h:718
CppVarPtr & firstVar()
Definition: cppast.h:714
CppTypeModifier & typeModifier()
Definition: cppast.h:463
std::string & baseType()
Definition: cppast.h:435
bool paramPack_
Definition: cppast.h:426
std::uint32_t typeAttr()
Definition: cppast.h:447
static constexpr CppObjType kObjectType
Definition: cppast.h:424
CppObj * compound()
Definition: cppast.h:443
Class to represent C++ variable definition.
Definition: cppast.h:565
CppVarType * varType()
Definition: cppast.h:589
CppTemplateParamList * templateParamList()
Definition: cppast.h:657
CppVarDecl & varDecl()
Definition: cppast.h:612
std::string & apidecor()
Definition: cppast.h:648
std::string & name()
Definition: cppast.h:598