2 * Contains C++ interfaces for interacting with DMD as a library.
4 * Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
5 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
6 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/cxxfrontend.d, _cxxfrontend.d)
8 * Documentation: https://dlang.org/phobos/dmd_cxxfrontend.html
9 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/cxxfrontend.d
11 module dmd
.cxxfrontend
;
13 import dmd
.aggregate
: AggregateDeclaration
;
14 import dmd
.arraytypes
;
16 import dmd
.common
.outbuffer
: OutBuffer
;
17 import dmd
.denum
: EnumDeclaration
;
18 import dmd
.dmodule
/*: Module*/;
19 import dmd
.dscope
: Scope
;
20 import dmd
.dstruct
/*: StructDeclaration*/;
21 import dmd
.dsymbol
: Dsymbol
, ScopeDsymbol
, CAsmDeclaration
, SearchOpt
, SearchOptFlags
;
22 import dmd
.dtemplate
/*: TemplateInstance, TemplateParameter, Tuple*/;
23 import dmd
.errorsink
: ErrorSink
;
24 import dmd
.expression
/*: Expression*/;
25 import dmd
.func
: FuncDeclaration
;
27 import dmd
.identifier
: Identifier
;
28 import dmd
.init
: Initializer
, NeedInterpret
;
29 import dmd
.location
: Loc
;
30 import dmd
.mtype
/*: Covariant, Type, Parameter, ParameterList*/;
31 import dmd
.rootobject
: RootObject
;
32 import dmd
.statement
: Statement
, AsmStatement
, GccAsmStatement
;
34 // NB: At some point in the future, we can switch to shortened function syntax.
37 /***********************************************************
40 const(char)* toCppMangleItanium(Dsymbol s
)
43 return dmd
.cppmangle
.toCppMangleItanium(s
);
46 const(char)* cppTypeInfoMangleItanium(Dsymbol s
)
49 return dmd
.cppmangle
.cppTypeInfoMangleItanium(s
);
52 const(char)* cppThunkMangleItanium(FuncDeclaration fd
, int offset
)
55 return dmd
.cppmangle
.cppThunkMangleItanium(fd
, offset
);
58 /***********************************************************
61 Expression
ctfeInterpret(Expression e
)
63 import dmd
.dinterpret
;
64 return dmd
.dinterpret
.ctfeInterpret(e
);
67 /***********************************************************
70 const(char)* mangleExact(FuncDeclaration fd
)
73 return dmd
.dmangle
.mangleExact(fd
);
76 void mangleToBuffer(Type t
, ref OutBuffer buf
)
79 return dmd
.dmangle
.mangleToBuffer(t
, buf
);
82 void mangleToBuffer(Expression e
, ref OutBuffer buf
)
85 return dmd
.dmangle
.mangleToBuffer(e
, buf
);
88 void mangleToBuffer(Dsymbol s
, ref OutBuffer buf
)
91 return dmd
.dmangle
.mangleToBuffer(s
, buf
);
94 void mangleToBuffer(TemplateInstance ti
, ref OutBuffer buf
)
97 return dmd
.dmangle
.mangleToBuffer(ti
, buf
);
100 /***********************************************************
103 void getLocalClasses(Module mod
, ref ClassDeclarations aclasses
)
105 return dmd
.dmodule
.getLocalClasses(mod
, aclasses
);
108 FuncDeclaration
findGetMembers(ScopeDsymbol dsym
)
110 return dmd
.dmodule
.findGetMembers(dsym
);
113 /***********************************************************
116 void gendocfile(Module m
, const char* ddoctext_ptr
, size_t ddoctext_length
,
117 const char* datetime
, ErrorSink eSink
, ref OutBuffer outbuf
)
120 return dmd
.doc
.gendocfile(m
, ddoctext_ptr
, ddoctext_length
, datetime
, eSink
, outbuf
);
123 /***********************************************************
126 FuncDeclaration
search_toString(StructDeclaration sd
)
128 return dmd
.dstruct
.search_toString(sd
);
131 /***********************************************************
134 void dsymbolSemantic(Dsymbol dsym
, Scope
* sc
)
136 import dmd
.dsymbolsem
;
137 return dmd
.dsymbolsem
.dsymbolSemantic(dsym
, sc
);
140 void addMember(Dsymbol dsym
, Scope
* sc
, ScopeDsymbol sds
)
142 import dmd
.dsymbolsem
;
143 return dmd
.dsymbolsem
.addMember(dsym
, sc
, sds
);
146 Dsymbol
search(Dsymbol d
, const ref Loc loc
, Identifier ident
, SearchOptFlags
147 flags
= SearchOpt
.all
)
149 import dmd
.dsymbolsem
;
150 return dmd
.dsymbolsem
.search(d
, loc
, ident
, flags
);
153 void setScope(Dsymbol d
, Scope
* sc
)
155 import dmd
.dsymbolsem
;
156 return dmd
.dsymbolsem
.setScope(d
, sc
);
159 void importAll(Dsymbol d
, Scope
* sc
)
161 import dmd
.dsymbolsem
;
162 return dmd
.dsymbolsem
.importAll(d
, sc
);
165 /***********************************************************
168 inout(Expression
) isExpression(inout RootObject o
)
170 return dmd
.dtemplate
.isExpression(o
);
173 inout(Dsymbol
) isDsymbol(inout RootObject o
)
175 return dmd
.dtemplate
.isDsymbol(o
);
178 inout(Type
) isType(inout RootObject o
)
180 return dmd
.dtemplate
.isType(o
);
183 inout(Tuple
) isTuple(inout RootObject o
)
185 return dmd
.dtemplate
.isTuple(o
);
188 inout(Parameter
) isParameter(inout RootObject o
)
190 return dmd
.dtemplate
.isParameter(o
);
193 inout(TemplateParameter
) isTemplateParameter(inout RootObject o
)
195 return dmd
.dtemplate
.isTemplateParameter(o
);
198 bool isError(const RootObject o
)
200 return dmd
.dtemplate
.isError(o
);
203 void printTemplateStats(bool listInstances
, ErrorSink eSink
)
205 return dmd
.dtemplate
.printTemplateStats(listInstances
, eSink
);
208 /***********************************************************
211 void genCppHdrFiles(ref Modules ms
)
214 return dmd
.dtoh
.genCppHdrFiles(ms
);
217 /***********************************************************
220 Expression
getDefaultValue(EnumDeclaration ed
, const ref Loc loc
)
223 return dmd
.enumsem
.getDefaultValue(ed
, loc
);
226 /***********************************************************
229 void expandTuples(Expressions
* exps
, Identifiers
* names
= null)
231 return dmd
.expression
.expandTuples(exps
, names
);
234 /***********************************************************
237 Expression
expressionSemantic(Expression e
, Scope
* sc
)
239 import dmd
.expressionsem
;
240 return dmd
.expressionsem
.expressionSemantic(e
, sc
);
243 /***********************************************************
246 bool functionSemantic(FuncDeclaration fd
)
249 return dmd
.funcsem
.functionSemantic(fd
);
252 bool functionSemantic3(FuncDeclaration fd
)
255 return dmd
.funcsem
.functionSemantic3(fd
);
258 /***********************************************************
261 void genhdrfile(Module m
, bool doFuncBodies
, ref OutBuffer buf
)
264 return dmd
.hdrgen
.genhdrfile(m
, doFuncBodies
, buf
);
267 const(char)* toChars(const Statement s
)
270 return dmd
.hdrgen
.toChars(s
);
273 const(char)* toChars(const Expression e
)
276 return dmd
.hdrgen
.toChars(e
);
279 const(char)* toChars(const Initializer i
)
282 return dmd
.hdrgen
.toChars(i
);
285 const(char)* toChars(const Type t
)
288 return dmd
.hdrgen
.toChars(t
);
291 void moduleToBuffer(ref OutBuffer buf
, bool vcg_ast
, Module m
)
294 return dmd
.hdrgen
.moduleToBuffer(buf
, vcg_ast
, m
);
297 const(char)* parametersTypeToChars(ParameterList pl
)
300 return dmd
.hdrgen
.parametersTypeToChars(pl
);
303 /***********************************************************
306 Statement
asmSemantic(AsmStatement s
, Scope
*sc
)
309 return dmd
.iasm
.asmSemantic(s
, sc
);
312 void asmSemantic(CAsmDeclaration d
, Scope
*sc
)
315 return dmd
.iasm
.asmSemantic(d
, sc
);
318 /***********************************************************
321 Statement
gccAsmSemantic(GccAsmStatement s
, Scope
*sc
)
324 return dmd
.iasmgcc
.gccAsmSemantic(s
, sc
);
327 void gccAsmSemantic(CAsmDeclaration d
, Scope
*sc
)
330 return dmd
.iasmgcc
.gccAsmSemantic(d
, sc
);
333 /***********************************************************
336 Initializer
initializerSemantic(Initializer init
, Scope
* sc
, ref Type tx
,
337 NeedInterpret needInterpret
)
340 return dmd
.initsem
.initializerSemantic(init
, sc
, tx
, needInterpret
);
343 Expression
initializerToExpression(Initializer init
, Type itype
= null, const
344 bool isCfile
= false)
347 return dmd
.initsem
.initializerToExpression(init
, itype
, isCfile
);
350 /***********************************************************
353 void json_generate(ref Modules modules
, ref OutBuffer buf
)
356 return dmd
.json
.json_generate(modules
, buf
);
359 JsonFieldFlags
tryParseJsonField(const(char)* fieldName
)
362 return dmd
.json
.tryParseJsonField(fieldName
);
365 /***********************************************************
368 AggregateDeclaration
isAggregate(Type t
)
370 return dmd
.mtype
.isAggregate(t
);
373 /***********************************************************
376 Expression
optimize(Expression e
, int result
, bool keepLvalue
= false)
379 return dmd
.optimize
.optimize(e
, result
, keepLvalue
);
382 /***********************************************************
385 void semantic2(Dsymbol dsym
, Scope
* sc
)
387 import dmd
.semantic2
;
388 return dmd
.semantic2
.semantic2(dsym
, sc
);
391 /***********************************************************
394 void semantic3(Dsymbol dsym
, Scope
* sc
)
396 import dmd
.semantic3
;
397 return dmd
.semantic3
.semantic3(dsym
, sc
);
400 void semanticTypeInfoMembers(StructDeclaration sd
)
402 import dmd
.semantic3
;
403 return dmd
.semantic3
.semanticTypeInfoMembers(sd
);
406 /***********************************************************
409 Statement
statementSemantic(Statement s
, Scope
* sc
)
411 import dmd
.statementsem
;
412 return dmd
.statementsem
.statementSemantic(s
, sc
);
415 /***********************************************************
418 bool tpsemantic(TemplateParameter tp
, Scope
* sc
, TemplateParameters
* parameters
)
420 import dmd
.templateparamsem
;
421 return dmd
.templateparamsem
.tpsemantic(tp
, sc
, parameters
);
424 /***********************************************************
427 bool hasPointers(Type t
)
430 return dmd
.typesem
.hasPointers(t
);
433 Type
typeSemantic(Type type
, const ref Loc loc
, Scope
* sc
)
436 return dmd
.typesem
.typeSemantic(type
, loc
, sc
);
439 Type
trySemantic(Type type
, const ref Loc loc
, Scope
* sc
)
442 return dmd
.typesem
.trySemantic(type
, loc
, sc
);
445 Type
merge(Type type
)
448 return dmd
.typesem
.merge(type
);
451 Type
merge2(Type type
)
454 return dmd
.typesem
.merge2(type
);
457 Expression
defaultInit(Type mt
, const ref Loc loc
, const bool isCfile
= false)
460 return dmd
.typesem
.defaultInit(mt
, loc
, isCfile
);
463 Dsymbol
toDsymbol(Type type
, Scope
* sc
)
466 return dmd
.typesem
.toDsymbol(type
, sc
);
469 Covariant
covariant(Type src
, Type t
, StorageClass
* pstc
= null, bool
470 cppCovariant
= false)
473 return dmd
.typesem
.covariant(src
, t
, pstc
, cppCovariant
);
476 bool isBaseOf(Type tthis
, Type t
, int* poffset
)
479 return dmd
.typesem
.isBaseOf(tthis
, t
, poffset
);
482 bool equivalent(Type src
, Type t
)
485 return dmd
.typesem
.equivalent(src
, t
);
488 Type
sarrayOf(Type type
, dinteger_t dim
)
491 return dmd
.typesem
.sarrayOf(type
, dim
);
494 Type
arrayOf(Type type
)
497 return dmd
.typesem
.arrayOf(type
);
500 Type
constOf(Type type
)
503 return dmd
.typesem
.constOf(type
);
506 Type
immutableOf(Type type
)
509 return dmd
.typesem
.immutableOf(type
);
512 Type
mutableOf(Type type
)
515 return dmd
.typesem
.mutableOf(type
);
518 Type
sharedOf(Type type
)
521 return dmd
.typesem
.sharedOf(type
);
524 Type
sharedConstOf(Type type
)
527 return dmd
.typesem
.sharedConstOf(type
);
530 Type
unSharedOf(Type type
)
533 return dmd
.typesem
.unSharedOf(type
);
536 Type
wildOf(Type type
)
539 return dmd
.typesem
.wildOf(type
);
542 Type
wildConstOf(Type type
)
545 return dmd
.typesem
.wildConstOf(type
);
548 Type
sharedWildOf(Type type
)
551 return dmd
.typesem
.sharedWildOf(type
);
554 Type
sharedWildConstOf(Type type
)
557 return dmd
.typesem
.sharedWildConstOf(type
);
560 Type
substWildTo(Type type
, uint mod
)
563 return dmd
.typesem
.substWildTo(type
, mod
);
566 Type
unqualify(Type type
, uint m
)
569 return dmd
.typesem
.unqualify(type
, m
);
572 Type
toHeadMutable(const(Type
) type
)
575 return dmd
.typesem
.toHeadMutable(type
);
578 Type
aliasthisOf(Type type
)
581 return dmd
.typesem
.aliasthisOf(type
);
584 Type
castMod(Type type
, MOD mod
)
587 return dmd
.typesem
.castMod(type
, mod
);
590 Type
addMod(Type type
, MOD mod
)
593 return dmd
.typesem
.addMod(type
, mod
);
596 Type
addStorageClass(Type type
, StorageClass
stc)
599 return dmd
.typesem
.addStorageClass(type
, stc);
602 Type
pointerTo(Type type
)
605 return dmd
.typesem
.pointerTo(type
);
608 Type
referenceTo(Type type
)
611 return dmd
.typesem
.referenceTo(type
);
614 /***********************************************************
617 bool genTypeInfo(Expression e
, const ref Loc loc
, Type torig
, Scope
* sc
)
620 return dmd
.typinf
.genTypeInfo(e
, loc
, torig
, sc
);
623 bool isSpeculativeType(Type t
)
626 return dmd
.typinf
.isSpeculativeType(t
);
629 bool builtinTypeInfo(Type t
)
632 return dmd
.typinf
.builtinTypeInfo(t
);
637 /***********************************************************
640 TypeTuple
toArgTypes_aarch64(Type t
)
642 import dmd
.argtypes_aarch64
;
643 return dmd
.argtypes_aarch64
.toArgTypes_aarch64(t
);
646 bool isHFVA(Type t
, int maxNumElements
= 4, Type
* rewriteType
= null)
648 import dmd
.argtypes_aarch64
;
649 return dmd
.argtypes_aarch64
.isHFVA(t
, maxNumElements
, rewriteType
);
652 /***********************************************************
653 * argtypes_sysv_x64.d
655 TypeTuple
toArgTypes_sysv_x64(Type t
)
657 import dmd
.argtypes_sysv_x64
;
658 return dmd
.argtypes_sysv_x64
.toArgTypes_sysv_x64(t
);
661 /***********************************************************
664 TypeTuple
toArgTypes_x86(Type t
)
666 import dmd
.argtypes_x86
;
667 return dmd
.argtypes_x86
.toArgTypes_x86(t
);