Skip to content

Commit 418beda

Browse files
committed
Parser improvements
1 parent 0f3badd commit 418beda

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

src/CppParser/Parser.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ Parser::Parser(CppParserOptions* Opts)
165165
{
166166
supportedStdTypes.insert("allocator");
167167
supportedStdTypes.insert("basic_string");
168+
169+
walkedNamespaces.reserve(8192);
170+
walkedTypeTemplateParameters.reserve(8192);
171+
walkedTemplateTemplateParameters.reserve(32);
172+
walkedNonTypeTemplateParameters.reserve(1024);
173+
walkedParameters.reserve(65536);
168174
}
169175

170176
LayoutField Parser::WalkVTablePointer(Class* Class,
@@ -424,27 +430,23 @@ void Parser::Setup(bool Compile)
424430
if (opts->verbose)
425431
HSOpts.Verbose = true;
426432

427-
for (unsigned I = 0, E = opts->IncludeDirs.size(); I != E; ++I)
433+
for (const auto& s : opts->IncludeDirs)
428434
{
429-
const auto& s = opts->IncludeDirs[I];
430435
HSOpts.AddPath(s, frontend::Angled, false, false);
431436
}
432437

433-
for (unsigned I = 0, E = opts->SystemIncludeDirs.size(); I != E; ++I)
438+
for (const auto& s : opts->SystemIncludeDirs)
434439
{
435-
const auto& s = opts->SystemIncludeDirs[I];
436440
HSOpts.AddPath(s, frontend::System, false, false);
437441
}
438442

439-
for (unsigned I = 0, E = opts->Defines.size(); I != E; ++I)
443+
for (const auto& define : opts->Defines)
440444
{
441-
const auto& define = opts->Defines[I];
442445
PPOpts.addMacroDef(define);
443446
}
444447

445-
for (unsigned I = 0, E = opts->Undefines.size(); I != E; ++I)
448+
for (const auto& undefine : opts->Undefines)
446449
{
447-
const auto& undefine = opts->Undefines[I];
448450
PPOpts.addMacroUndef(undefine);
449451
}
450452

@@ -480,8 +482,7 @@ void Parser::Setup(bool Compile)
480482
}
481483
}
482484

483-
if (TC)
484-
delete TC;
485+
delete TC;
485486

486487
// Enable preprocessing record.
487488
PPOpts.DetailedRecord = true;
@@ -2537,7 +2538,7 @@ Type* Parser::WalkType(clang::QualType QualType, const clang::TypeLoc* TL, bool
25372538
EnumDecl* ED = ET->getDecl();
25382539

25392540
auto TT = new AST::TagType();
2540-
TT->declaration = TT->declaration = WalkDeclaration(ED);
2541+
TT->declaration = WalkDeclaration(ED);
25412542

25422543
Ty = TT;
25432544
break;
@@ -4430,8 +4431,8 @@ Declaration* Parser::WalkDeclaration(const clang::Decl* D)
44304431
{
44314432
auto MD = cast<CXXMethodDecl>(D);
44324433
Decl = WalkMethodCXX(MD);
4433-
if (Decl == nullptr)
4434-
return Decl;
4434+
if (!Decl)
4435+
return nullptr;
44354436

44364437
auto NS = GetNamespace(MD);
44374438
Decl->_namespace = NS;
@@ -4609,7 +4610,7 @@ void Parser::SetupLLVMCodegen()
46094610
c->getHeaderSearchOpts(), c->getPreprocessorOpts(),
46104611
c->getCodeGenOpts(), *LLVMModule, c->getDiagnostics()));
46114612

4612-
codeGenTypes.reset(new clang::CodeGen::CodeGenTypes(*CGM.get()));
4613+
codeGenTypes.reset(new clang::CodeGen::CodeGenTypes(*CGM));
46134614
}
46144615

46154616
bool Parser::SetupSourceFiles(const std::vector<std::string>& SourceFiles,
@@ -4710,7 +4711,7 @@ ParserResult* Parser::Parse(const std::vector<std::string>& SourceFiles)
47104711

47114712
DiagClient->BeginSourceFile(c->getLangOpts(), &c->getPreprocessor());
47124713

4713-
ParseAST(c->getSema());
4714+
ParseAST(c->getSema(), opts->verbose, opts->skipFunctionBodies);
47144715

47154716
DiagClient->EndSourceFile();
47164717

0 commit comments

Comments
 (0)