Skip to content

Commit 88204f7

Browse files
authored
Fix/parser improvements (#1919)
* Parser improvements * Fix AST Converter missing conversion data * Fix bug in test code Can't return `T();` if `T` is a const reference type. * Fix other test compile bug It's kinda weird to call it pure virtual and then implement it anyway no? * Fix test compiler error Don't skip function bodies to force template instantiations * Fix clang assert
1 parent 7105da0 commit 88204f7

File tree

8 files changed

+230
-221
lines changed

8 files changed

+230
-221
lines changed

src/CppParser/Bootstrap/StmtCodeGenerators.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,20 @@ public override bool VisitProperty(Property property)
341341
WriteLine($"_S->{fieldName} = static_cast<AST::{typeName}>(" +
342342
$"WalkStatement(S->{methodName}()));");
343343
else if (typeName.Contains("Expr"))
344-
WriteLine($"_S->{fieldName} = static_cast<AST::{typeName}>(" +
345-
$"WalkExpression(S->{methodName}()));");
344+
{
345+
var expr = $"_S->{fieldName} = static_cast<AST::{typeName}>(WalkExpression(S->{methodName}()));";
346+
347+
if (fieldName == "base" && typeName is "CXXDependentScopeMemberExpr")
348+
{
349+
// Clang asserts that 'getBase()' is not called when 'isImplicitAccess()' returns true
350+
WriteLine("if (!S->isImplicitAccess())");
351+
WriteLineIndent(expr);
352+
}
353+
else
354+
{
355+
WriteLine(expr);
356+
}
357+
}
346358
else if (fieldName == "guidDecl")
347359
WriteLine($"_S->{fieldName} = S->getGuidDecl()->getNameAsString();");
348360
else if (typeName.Contains("Decl") || typeName.Contains("Method") ||

src/CppParser/ParseExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,7 +2426,8 @@ AST::Expr* Parser::WalkExpression(const clang::Expr* Expr)
24262426
_S->refersToMatrixElement = S->refersToMatrixElement();
24272427
_S->hasPlaceholderType = S->hasPlaceholderType();
24282428
_S->isImplicitAccess = S->isImplicitAccess();
2429-
_S->base = static_cast<AST::Expr*>(WalkExpression(S->getBase()));
2429+
if (!S->isImplicitAccess())
2430+
_S->base = static_cast<AST::Expr*>(WalkExpression(S->getBase()));
24302431
_S->baseType = GetQualifiedType(S->getBaseType());
24312432
_S->isArrow = S->isArrow();
24322433
_S->firstQualifierFoundInScope = static_cast<AST::Declaration*>(WalkDeclaration(S->getFirstQualifierFoundInScope()));

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

src/Generator/Passes/SymbolsCodeGenerator.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,7 @@ private void WrapConstructor(Method method, string wrapper, string @params)
162162
bool isAbstract = ((Class)method.Namespace).IsAbstract;
163163
if (method.Access == AccessSpecifier.Protected || isAbstract)
164164
{
165-
Write($@"{{ ::new ({Helpers.InstanceField}) {
166-
wrapper}{method.Namespace.Name}({@params}); }}");
165+
Write($@"{{ ::new ({Helpers.InstanceField}) {wrapper}{method.Namespace.Name}({@params}); }}");
167166
WriteLine(!isAbstract ? " };" : string.Empty);
168167
}
169168
else
@@ -210,12 +209,10 @@ private void WrapDestructor(Method method, string wrapper)
210209
{
211210
string @class = wrapper + method.Namespace.Name;
212211
WriteLine($"() {{ this->~{@class}(); }} }};");
213-
Write($@"extern ""C"" {GetExporting()}void {wrapper}({
214-
@class}* {instance}) {{ {instance}->{wrapper}Protected");
212+
Write($@"extern ""C"" {GetExporting()}void {wrapper}({@class}* {instance}) {{ {instance}->{wrapper}Protected");
215213
}
216214
else
217-
Write($@"({$"{@namespace}*{instance}"}) {{ {
218-
instance}->~{method.Namespace.Name}");
215+
Write($@"({$"{@namespace}*{instance}"}) {{ {instance}->~{method.Namespace.Name}");
219216
WriteLine("(); }");
220217
}
221218

@@ -238,8 +235,7 @@ private void TakeFunctionAddress(Function function, string wrapper)
238235

239236
var method = function as Method;
240237
if (function.Namespace.Access == AccessSpecifier.Protected)
241-
Write($@"class {wrapper}{function.Namespace.Name} : public {
242-
function.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
238+
Write($@"class {wrapper}{function.Namespace.Name} : public {function.Namespace.Namespace.Visit(cppTypePrinter)} {{ ");
243239

244240
string variable = $@"({(method?.IsStatic == false ?
245241
(@namespace + "::") : string.Empty)}*{wrapper}){signature}";

0 commit comments

Comments
 (0)