diff --git a/dub.sdl b/dub.sdl index 3894cdc0..d8d31c79 100644 --- a/dub.sdl +++ b/dub.sdl @@ -9,7 +9,7 @@ targetPath "bin" targetName "d++" dependency "libclang" version="~>0.3.1" -dependency "sumtype" version="~>0.7.1" +dependency "sumtype" version="~>1.2.0" versions "SumTypeNoDefaultCtor" diff --git a/source/dpp/clang/package.d b/source/dpp/clang/package.d index 1c8077d8..dd97a6a7 100644 --- a/source/dpp/clang/package.d +++ b/source/dpp/clang/package.d @@ -118,3 +118,7 @@ bool hasAnonymousSpelling(in string spelling) @safe pure nothrow { import std.algorithm : canFind; return spelling.canFind("(anonymous") || spelling.canFind("(unnamed"); } + +bool isSortaAnonymous(in from!"clang".Cursor cursor) @safe pure nothrow { + return cursor.spelling == "" || cursor.isAnonymous; +} diff --git a/source/dpp/runtime/context.d b/source/dpp/runtime/context.d index 6ed23e53..d3e071ff 100644 --- a/source/dpp/runtime/context.d +++ b/source/dpp/runtime/context.d @@ -371,7 +371,8 @@ struct Context { /// return the spelling if it exists, or our made-up nickname for it if not string spellingOrNickname(in Cursor cursor) @safe pure { - if (cursor.spelling == "" || cursor.isAnonymous) + import dpp.clang: isSortaAnonymous; + if (cursor.isSortaAnonymous) return nickName(cursor); return spelling(cursor.spelling); diff --git a/source/dpp/translation/translation.d b/source/dpp/translation/translation.d index c27be99e..348d30f8 100644 --- a/source/dpp/translation/translation.d +++ b/source/dpp/translation/translation.d @@ -30,6 +30,7 @@ private bool skipTopLevel(in from!"clang".Cursor cursor, @safe { import dpp.translation.aggregate: isAggregateC; + import dpp.clang: isSortaAnonymous; import clang: Cursor; import std.algorithm: startsWith, canFind; @@ -37,12 +38,11 @@ private bool skipTopLevel(in from!"clang".Cursor cursor, return true; // We want to ignore anonymous structs and unions but not enums. See #54 - if((cursor.spelling == "" || cursor.isAnonymous) && cursor.kind == Cursor.Kind.EnumDecl) + if((cursor.isSortaAnonymous) && cursor.kind == Cursor.Kind.EnumDecl) return false; // don't bother translating top-level anonymous aggregates - const isAnon = cursor.spelling == "" || cursor.isAnonymous; - if(isAggregateC(cursor) && isAnon) + if(isAggregateC(cursor) && cursor.isSortaAnonymous) return true; if(context.options.ignoreMacros && cursor.kind == Cursor.Kind.MacroDefinition) diff --git a/source/dpp/translation/typedef_.d b/source/dpp/translation/typedef_.d index dca9b3fa..56731d47 100644 --- a/source/dpp/translation/typedef_.d +++ b/source/dpp/translation/typedef_.d @@ -72,11 +72,12 @@ string[] translateNonFunction(in from!"clang".Cursor cursor, private bool isTopLevelAnonymous(in from!"clang".Cursor[] children) @safe nothrow { + import dpp.clang: isSortaAnonymous; import clang: Cursor; return children.length == 1 && // so we can inspect it - (children[0].spelling == "" || children[0].isAnonymous) && // anonymous + children[0].isSortaAnonymous && // anonymous children[0].lexicalParent.kind == Cursor.Kind.TranslationUnit && // top-level children[0].kind != Cursor.Kind.ParmDecl // a lot more should be here ; @@ -91,6 +92,7 @@ private string[] translateRegular(in from!"clang".Cursor cursor, import dpp.translation.type: translate, removeDppDecorators; import dpp.translation.aggregate: isAggregateC; import dpp.translation.dlang: maybeRename; + import dpp.clang: isSortaAnonymous; import clang: Type; import std.typecons: No; @@ -102,7 +104,7 @@ private string[] translateRegular(in from!"clang".Cursor cursor, const isAnonymousEnum = children.length == 1 && isAggregateC(children[0]) && - children[0].spelling == "" && + children[0].isSortaAnonymous && children[0].type.kind == Type.Kind.Enum ;