Skip to content

Commit 3b3c04d

Browse files
committed
Fix clang assert
1 parent b55c2b3 commit 3b3c04d

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

src/CppParser/Bootstrap/Bootstrap.cs

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ private void GenerateExpr(BindingContext ctx)
154154
var specifiersUnit = ctx.ASTContext.TranslationUnits.Find(unit =>
155155
unit.FileName == "Specifiers.h");
156156
var nonOdrUseReason = specifiersUnit.FindEnum("clang::NonOdrUseReason");
157-
157+
158158
var apFloatUnit = ctx.ASTContext.TranslationUnits.Find(unit =>
159159
unit.FileName == "APFloat.h");
160160
var floatSemantics = apFloatUnit
@@ -165,7 +165,7 @@ private void GenerateExpr(BindingContext ctx)
165165
// Move to outer namespace
166166
floatSemantics.Namespace = floatSemantics.Namespace.Namespace.Namespace;
167167

168-
var decls = new Declaration[] {
168+
var decls = new Declaration[] {
169169
operationKindsUnit, operatorKindsUnit,
170170
unaryExprOrTypeTrait, nonOdrUseReason,
171171
exprDependence, floatSemantics
@@ -340,7 +340,7 @@ private static void Check(Declaration decl)
340340

341341
if (decl.Name == "EmptyShell")
342342
decl.ExplicitlyIgnore();
343-
343+
344344
if (decl.Name == "DecomposedForm")
345345
decl.ExplicitlyIgnore();
346346

@@ -613,8 +613,7 @@ public override bool VisitClassDecl(Class @class)
613613
var iteratorTypeName = GetIteratorTypeName(iteratorType, TypePrinter);
614614
var declName = GetDeclName(method, GeneratorKind.CSharp);
615615

616-
WriteLine($@"public List<{iteratorTypeName}> {
617-
declName} {{ get; private set; }} = new List<{iteratorTypeName}>();");
616+
WriteLine($@"public List<{iteratorTypeName}> {declName} {{ get; private set; }} = new List<{iteratorTypeName}>();");
618617
}
619618

620619
foreach (var property in @class.Properties)
@@ -1192,7 +1191,7 @@ private string GenerateInit(Property property)
11921191
{
11931192
if (property.Type.IsPointer())
11941193
return "nullptr";
1195-
1194+
11961195
if (property.Type.IsPrimitiveType(PrimitiveType.Bool))
11971196
return "false";
11981197

@@ -1202,7 +1201,7 @@ private string GenerateInit(Property property)
12021201

12031202
if (property.Type.TryGetEnum(out Enumeration @enum))
12041203
return $"{GetQualifiedName(@enum)}::{@enum.Items.First().Name}";
1205-
1204+
12061205
return "0";
12071206
}
12081207

@@ -1233,7 +1232,7 @@ public void GenerateParser()
12331232
WriteInclude("Parser.h", CInclude.IncludeKind.Quoted);
12341233
GenerateIncludes();
12351234
NewLine();
1236-
1235+
12371236
WriteLine("namespace CppSharp::CppParser {");
12381237
NewLine();
12391238

@@ -1259,7 +1258,7 @@ private void GenerateWalkStatement()
12591258
WriteLine(MethodSig);
12601259
WriteOpenBraceAndIndent();
12611260

1262-
WriteLine($"if (!{BaseTypeName })");
1261+
WriteLine($"if (!{BaseTypeName})");
12631262
WriteLineIndent("return nullptr;");
12641263
NewLine();
12651264

@@ -1401,8 +1400,19 @@ public override bool VisitProperty(Property property)
14011400
WriteLine($"_S->{fieldName} = static_cast<AST::{typeName}>(" +
14021401
$"WalkStatement(S->{methodName}()));");
14031402
else if (typeName.Contains("Expr"))
1404-
WriteLine($"_S->{fieldName} = static_cast<AST::{typeName}>(" +
1405-
$"WalkExpression(S->{methodName}()));");
1403+
{
1404+
var expr = $"_S->{fieldName} = static_cast<AST::{typeName}>(WalkExpression(S->{methodName}()));";
1405+
1406+
if (fieldName == "base")
1407+
{
1408+
WriteLine("if (!S->isImplicitAccess())");
1409+
WriteLineIndent(expr);
1410+
}
1411+
else
1412+
{
1413+
WriteLine(expr);
1414+
}
1415+
}
14061416
else if (fieldName == "guidDecl")
14071417
WriteLine($"_S->{fieldName} = S->getGuidDecl()->getNameAsString();");
14081418
else if (typeName.Contains("Decl") || typeName.Contains("Method") ||
@@ -1565,18 +1575,18 @@ static class CodeGeneratorHelpers
15651575
public static bool IsAbstractStmt(Class @class) => IsAbstractStmt(@class.Name);
15661576

15671577
public static bool IsAbstractStmt(string className) =>
1568-
className is "Stmt"
1569-
or "ValueStmt"
1570-
or "NoStmt"
1571-
or "SwitchCase"
1572-
or "AsmStmt"
1573-
or "Expr"
1574-
or "FullExpr"
1575-
or "CastExpr"
1576-
or "ExplicitCastExpr"
1577-
or "AbstractConditionalOperator"
1578-
or "CXXNamedCastExpr"
1579-
or "OverloadExpr"
1578+
className is "Stmt"
1579+
or "ValueStmt"
1580+
or "NoStmt"
1581+
or "SwitchCase"
1582+
or "AsmStmt"
1583+
or "Expr"
1584+
or "FullExpr"
1585+
or "CastExpr"
1586+
or "ExplicitCastExpr"
1587+
or "AbstractConditionalOperator"
1588+
or "CXXNamedCastExpr"
1589+
or "OverloadExpr"
15801590
or "CoroutineSuspendExpr";
15811591

15821592
public static bool SkipProperty(Property property, bool skipBaseCheck = false)
@@ -1748,7 +1758,7 @@ public static bool SkipProperty(Property property, bool skipBaseCheck = false)
17481758
// UnresolvedMemberExpr
17491759
if (typeName.Contains("DeclarationName"))
17501760
return true;
1751-
1761+
17521762
// SubstNonTypeTemplateParmExpr
17531763
// SubstNonTypeTemplateParmPackExpr
17541764
if (typeName.Contains("NonTypeTemplateParmDecl"))
@@ -1780,7 +1790,7 @@ public static bool SkipProperty(Property property, bool skipBaseCheck = false)
17801790
// CXXRewrittenBinaryOperator
17811791
if (typeName.Contains("DecomposedForm"))
17821792
return true;
1783-
1793+
17841794
if (typeName.Contains("optional"))
17851795
return true;
17861796

@@ -1939,9 +1949,9 @@ public static string GetDeclTypeName(AST.Type type,
19391949
var typeResult = declType.Visit(typePrinter);
19401950

19411951
if (typeResult.Type.Contains("MSGuidDecl"))
1942-
return typePrinter is CppTypePrinter
1952+
return typePrinter is CppTypePrinter
19431953
? "std::string" : "string";
1944-
1954+
19451955
var typeName = typeResult.ToString();
19461956
typeName = CleanClangNamespaceFromName(typeName);
19471957

@@ -1951,7 +1961,7 @@ public static string GetDeclTypeName(AST.Type type,
19511961
typeName = "UnaryOperatorKind";
19521962
else if (typeName.Contains("BinaryOperator::Opcode"))
19531963
typeName = "BinaryOperatorKind";
1954-
1964+
19551965
else if (typeName.Contains("Semantics"))
19561966
typeName = "FloatSemantics";
19571967

@@ -2037,15 +2047,15 @@ public static string GetIteratorTypeName(AST.Type iteratorType,
20372047

20382048
if (iteratorTypeName.Contains("ExprIterator"))
20392049
iteratorTypeName = "Expr";
2040-
2050+
20412051
else if (iteratorTypeName.Contains("StmtIterator"))
20422052
iteratorTypeName = "Stmt";
20432053

20442054
else if (iteratorTypeName.Contains("CastIterator"))
20452055
{
20462056
if (iteratorType is TypedefType typedefType)
20472057
iteratorType = typedefType.Declaration.Type;
2048-
2058+
20492059
var templateArg = ((TemplateSpecializationType)iteratorType).Arguments[0];
20502060
iteratorType = templateArg.Type.Type;
20512061

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()));

0 commit comments

Comments
 (0)