Add missing getDefaultValue() to frontend C++ interface

This commit is contained in:
Martin Kinkelin 2024-03-03 20:54:57 +01:00
parent 8b2fa980e9
commit 81cdec0f7a
3 changed files with 14 additions and 1 deletions

View file

@ -14,6 +14,7 @@ import dmd.aggregate : AggregateDeclaration;
import dmd.arraytypes; import dmd.arraytypes;
import dmd.astenums; import dmd.astenums;
import dmd.common.outbuffer : OutBuffer; import dmd.common.outbuffer : OutBuffer;
import dmd.denum : EnumDeclaration;
import dmd.dmodule /*: Module*/; import dmd.dmodule /*: Module*/;
import dmd.dscope : Scope; import dmd.dscope : Scope;
import dmd.dstruct /*: StructDeclaration*/; import dmd.dstruct /*: StructDeclaration*/;
@ -213,6 +214,15 @@ void genCppHdrFiles(ref Modules ms)
return dmd.dtoh.genCppHdrFiles(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 * expression.d
*/ */

View file

@ -40,6 +40,7 @@ class OverloadSet;
class StringExp; class StringExp;
class InterpExp; class InterpExp;
class LoweredAssignExp; class LoweredAssignExp;
class EnumDeclaration;
#ifdef IN_GCC #ifdef IN_GCC
typedef union tree_node Symbol; typedef union tree_node Symbol;
#elif IN_LLVM #elif IN_LLVM
@ -54,6 +55,8 @@ namespace dmd
Expression *expressionSemantic(Expression *e, Scope *sc); Expression *expressionSemantic(Expression *e, Scope *sc);
// in typesem.d // in typesem.d
Expression *defaultInit(Type *mt, const Loc &loc, const bool isCfile = false); 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. // Entry point for CTFE.
// A compile-time result is required. Give an error if not possible // A compile-time result is required. Give an error if not possible

View file

@ -153,7 +153,7 @@ public:
} }
// otherwise emit a void[] with the default initializer // otherwise emit a void[] with the default initializer
else { else {
Expression *defaultval = sd->getDefaultValue(decl->loc); Expression *defaultval = getDefaultValue(sd, decl->loc);
LLConstant *c = toConstElem(defaultval, gIR); LLConstant *c = toConstElem(defaultval, gIR);
b.push_void_array(c, sd->memtype, sd); b.push_void_array(c, sd->memtype, sd);
} }