From 81cdec0f7a884863ecf558e43e061cea943e47b2 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 3 Mar 2024 20:54:57 +0100 Subject: [PATCH] Add missing getDefaultValue() to frontend C++ interface --- dmd/cxxfrontend.d | 10 ++++++++++ dmd/expression.h | 3 +++ gen/typinf.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dmd/cxxfrontend.d b/dmd/cxxfrontend.d index 0056f43491..03920f0b0a 100644 --- a/dmd/cxxfrontend.d +++ b/dmd/cxxfrontend.d @@ -14,6 +14,7 @@ import dmd.aggregate : AggregateDeclaration; import dmd.arraytypes; import dmd.astenums; import dmd.common.outbuffer : OutBuffer; +import dmd.denum : EnumDeclaration; import dmd.dmodule /*: Module*/; import dmd.dscope : Scope; import dmd.dstruct /*: StructDeclaration*/; @@ -213,6 +214,15 @@ void genCppHdrFiles(ref Modules ms) return dmd.dtoh.genCppHdrFiles(ms); } +/*********************************************************** + * enumsem.d + */ +Expression getDefaultValue(EnumDeclaration ed, const ref Loc loc) +{ + import dmd.enumsem; + return dmd.enumsem.getDefaultValue(ed, loc); +} + /*********************************************************** * expression.d */ diff --git a/dmd/expression.h b/dmd/expression.h index 01c1b8a338..8213576fd4 100644 --- a/dmd/expression.h +++ b/dmd/expression.h @@ -40,6 +40,7 @@ class OverloadSet; class StringExp; class InterpExp; class LoweredAssignExp; +class EnumDeclaration; #ifdef IN_GCC typedef union tree_node Symbol; #elif IN_LLVM @@ -54,6 +55,8 @@ namespace dmd Expression *expressionSemantic(Expression *e, Scope *sc); // in typesem.d Expression *defaultInit(Type *mt, const Loc &loc, const bool isCfile = false); + // in enumsem.d + Expression *getDefaultValue(EnumDeclaration *ed, const Loc &loc); // Entry point for CTFE. // A compile-time result is required. Give an error if not possible diff --git a/gen/typinf.cpp b/gen/typinf.cpp index 50982155bf..c1a5f18b9a 100644 --- a/gen/typinf.cpp +++ b/gen/typinf.cpp @@ -153,7 +153,7 @@ public: } // otherwise emit a void[] with the default initializer else { - Expression *defaultval = sd->getDefaultValue(decl->loc); + Expression *defaultval = getDefaultValue(sd, decl->loc); LLConstant *c = toConstElem(defaultval, gIR); b.push_void_array(c, sd->memtype, sd); }