d: Merge upstream dmd, druntime 855353a1d9
[official-gcc.git] / gcc / d / dmd / cxxfrontend.d
bloba0432d2e1b46c8e07e44c5a2baf297d3234b541a
1 /**
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;
15 import dmd.astenums;
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;
26 import dmd.globals;
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.
35 extern (C++, "dmd"):
37 /***********************************************************
38 * cppmangle.d
40 const(char)* toCppMangleItanium(Dsymbol s)
42 import dmd.cppmangle;
43 return dmd.cppmangle.toCppMangleItanium(s);
46 const(char)* cppTypeInfoMangleItanium(Dsymbol s)
48 import dmd.cppmangle;
49 return dmd.cppmangle.cppTypeInfoMangleItanium(s);
52 const(char)* cppThunkMangleItanium(FuncDeclaration fd, int offset)
54 import dmd.cppmangle;
55 return dmd.cppmangle.cppThunkMangleItanium(fd, offset);
58 /***********************************************************
59 * dinterpret.d
61 Expression ctfeInterpret(Expression e)
63 import dmd.dinterpret;
64 return dmd.dinterpret.ctfeInterpret(e);
67 /***********************************************************
68 * dmangle.d
70 const(char)* mangleExact(FuncDeclaration fd)
72 import dmd.dmangle;
73 return dmd.dmangle.mangleExact(fd);
76 void mangleToBuffer(Type t, ref OutBuffer buf)
78 import dmd.dmangle;
79 return dmd.dmangle.mangleToBuffer(t, buf);
82 void mangleToBuffer(Expression e, ref OutBuffer buf)
84 import dmd.dmangle;
85 return dmd.dmangle.mangleToBuffer(e, buf);
88 void mangleToBuffer(Dsymbol s, ref OutBuffer buf)
90 import dmd.dmangle;
91 return dmd.dmangle.mangleToBuffer(s, buf);
94 void mangleToBuffer(TemplateInstance ti, ref OutBuffer buf)
96 import dmd.dmangle;
97 return dmd.dmangle.mangleToBuffer(ti, buf);
100 /***********************************************************
101 * dmodule.d
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 /***********************************************************
114 * doc.d
116 void gendocfile(Module m, const char* ddoctext_ptr, size_t ddoctext_length,
117 const char* datetime, ErrorSink eSink, ref OutBuffer outbuf)
119 import dmd.doc;
120 return dmd.doc.gendocfile(m, ddoctext_ptr, ddoctext_length, datetime, eSink, outbuf);
123 /***********************************************************
124 * dstruct.d
126 FuncDeclaration search_toString(StructDeclaration sd)
128 return dmd.dstruct.search_toString(sd);
131 /***********************************************************
132 * dsymbolsem.d
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 /***********************************************************
166 * dtemplate.d
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 /***********************************************************
209 * dtoh.d
211 void genCppHdrFiles(ref Modules ms)
213 import dmd.dtoh;
214 return dmd.dtoh.genCppHdrFiles(ms);
217 /***********************************************************
218 * enumsem.d
220 Expression getDefaultValue(EnumDeclaration ed, const ref Loc loc)
222 import dmd.enumsem;
223 return dmd.enumsem.getDefaultValue(ed, loc);
226 /***********************************************************
227 * expression.d
229 void expandTuples(Expressions* exps, Identifiers* names = null)
231 return dmd.expression.expandTuples(exps, names);
234 /***********************************************************
235 * expressionsem.d
237 Expression expressionSemantic(Expression e, Scope* sc)
239 import dmd.expressionsem;
240 return dmd.expressionsem.expressionSemantic(e, sc);
243 /***********************************************************
244 * funcsem.d
246 bool functionSemantic(FuncDeclaration fd)
248 import dmd.funcsem;
249 return dmd.funcsem.functionSemantic(fd);
252 bool functionSemantic3(FuncDeclaration fd)
254 import dmd.funcsem;
255 return dmd.funcsem.functionSemantic3(fd);
258 /***********************************************************
259 * hdrgen.d
261 void genhdrfile(Module m, bool doFuncBodies, ref OutBuffer buf)
263 import dmd.hdrgen;
264 return dmd.hdrgen.genhdrfile(m, doFuncBodies, buf);
267 const(char)* toChars(const Statement s)
269 import dmd.hdrgen;
270 return dmd.hdrgen.toChars(s);
273 const(char)* toChars(const Expression e)
275 import dmd.hdrgen;
276 return dmd.hdrgen.toChars(e);
279 const(char)* toChars(const Initializer i)
281 import dmd.hdrgen;
282 return dmd.hdrgen.toChars(i);
285 const(char)* toChars(const Type t)
287 import dmd.hdrgen;
288 return dmd.hdrgen.toChars(t);
291 void moduleToBuffer(ref OutBuffer buf, bool vcg_ast, Module m)
293 import dmd.hdrgen;
294 return dmd.hdrgen.moduleToBuffer(buf, vcg_ast, m);
297 const(char)* parametersTypeToChars(ParameterList pl)
299 import dmd.hdrgen;
300 return dmd.hdrgen.parametersTypeToChars(pl);
303 /***********************************************************
304 * iasm.d
306 Statement asmSemantic(AsmStatement s, Scope *sc)
308 import dmd.iasm;
309 return dmd.iasm.asmSemantic(s, sc);
312 void asmSemantic(CAsmDeclaration d, Scope *sc)
314 import dmd.iasm;
315 return dmd.iasm.asmSemantic(d, sc);
318 /***********************************************************
319 * iasmgcc.d
321 Statement gccAsmSemantic(GccAsmStatement s, Scope *sc)
323 import dmd.iasmgcc;
324 return dmd.iasmgcc.gccAsmSemantic(s, sc);
327 void gccAsmSemantic(CAsmDeclaration d, Scope *sc)
329 import dmd.iasmgcc;
330 return dmd.iasmgcc.gccAsmSemantic(d, sc);
333 /***********************************************************
334 * initsem.d
336 Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx,
337 NeedInterpret needInterpret)
339 import dmd.initsem;
340 return dmd.initsem.initializerSemantic(init, sc, tx, needInterpret);
343 Expression initializerToExpression(Initializer init, Type itype = null, const
344 bool isCfile = false)
346 import dmd.initsem;
347 return dmd.initsem.initializerToExpression(init, itype, isCfile);
350 /***********************************************************
351 * json.d
353 void json_generate(ref Modules modules, ref OutBuffer buf)
355 import dmd.json;
356 return dmd.json.json_generate(modules, buf);
359 JsonFieldFlags tryParseJsonField(const(char)* fieldName)
361 import dmd.json;
362 return dmd.json.tryParseJsonField(fieldName);
365 /***********************************************************
366 * mtype.d
368 AggregateDeclaration isAggregate(Type t)
370 return dmd.mtype.isAggregate(t);
373 /***********************************************************
374 * optimize.d
376 Expression optimize(Expression e, int result, bool keepLvalue = false)
378 import dmd.optimize;
379 return dmd.optimize.optimize(e, result, keepLvalue);
382 /***********************************************************
383 * semantic2.d
385 void semantic2(Dsymbol dsym, Scope* sc)
387 import dmd.semantic2;
388 return dmd.semantic2.semantic2(dsym, sc);
391 /***********************************************************
392 * semantic3.d
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 /***********************************************************
407 * statementsem.d
409 Statement statementSemantic(Statement s, Scope* sc)
411 import dmd.statementsem;
412 return dmd.statementsem.statementSemantic(s, sc);
415 /***********************************************************
416 * templateparamsem.d
418 bool tpsemantic(TemplateParameter tp, Scope* sc, TemplateParameters* parameters)
420 import dmd.templateparamsem;
421 return dmd.templateparamsem.tpsemantic(tp, sc, parameters);
424 /***********************************************************
425 * typesem.d
427 bool hasPointers(Type t)
429 import dmd.typesem;
430 return dmd.typesem.hasPointers(t);
433 Type typeSemantic(Type type, const ref Loc loc, Scope* sc)
435 import dmd.typesem;
436 return dmd.typesem.typeSemantic(type, loc, sc);
439 Type trySemantic(Type type, const ref Loc loc, Scope* sc)
441 import dmd.typesem;
442 return dmd.typesem.trySemantic(type, loc, sc);
445 Type merge(Type type)
447 import dmd.typesem;
448 return dmd.typesem.merge(type);
451 Type merge2(Type type)
453 import dmd.typesem;
454 return dmd.typesem.merge2(type);
457 Expression defaultInit(Type mt, const ref Loc loc, const bool isCfile = false)
459 import dmd.typesem;
460 return dmd.typesem.defaultInit(mt, loc, isCfile);
463 Dsymbol toDsymbol(Type type, Scope* sc)
465 import dmd.typesem;
466 return dmd.typesem.toDsymbol(type, sc);
469 Covariant covariant(Type src, Type t, StorageClass* pstc = null, bool
470 cppCovariant = false)
472 import dmd.typesem;
473 return dmd.typesem.covariant(src, t, pstc, cppCovariant);
476 bool isBaseOf(Type tthis, Type t, int* poffset)
478 import dmd.typesem;
479 return dmd.typesem.isBaseOf(tthis, t, poffset);
482 bool equivalent(Type src, Type t)
484 import dmd.typesem;
485 return dmd.typesem.equivalent(src, t);
488 Type sarrayOf(Type type, dinteger_t dim)
490 import dmd.typesem;
491 return dmd.typesem.sarrayOf(type, dim);
494 Type arrayOf(Type type)
496 import dmd.typesem;
497 return dmd.typesem.arrayOf(type);
500 Type constOf(Type type)
502 import dmd.typesem;
503 return dmd.typesem.constOf(type);
506 Type immutableOf(Type type)
508 import dmd.typesem;
509 return dmd.typesem.immutableOf(type);
512 Type mutableOf(Type type)
514 import dmd.typesem;
515 return dmd.typesem.mutableOf(type);
518 Type sharedOf(Type type)
520 import dmd.typesem;
521 return dmd.typesem.sharedOf(type);
524 Type sharedConstOf(Type type)
526 import dmd.typesem;
527 return dmd.typesem.sharedConstOf(type);
530 Type unSharedOf(Type type)
532 import dmd.typesem;
533 return dmd.typesem.unSharedOf(type);
536 Type wildOf(Type type)
538 import dmd.typesem;
539 return dmd.typesem.wildOf(type);
542 Type wildConstOf(Type type)
544 import dmd.typesem;
545 return dmd.typesem.wildConstOf(type);
548 Type sharedWildOf(Type type)
550 import dmd.typesem;
551 return dmd.typesem.sharedWildOf(type);
554 Type sharedWildConstOf(Type type)
556 import dmd.typesem;
557 return dmd.typesem.sharedWildConstOf(type);
560 Type substWildTo(Type type, uint mod)
562 import dmd.typesem;
563 return dmd.typesem.substWildTo(type, mod);
566 Type unqualify(Type type, uint m)
568 import dmd.typesem;
569 return dmd.typesem.unqualify(type, m);
572 Type toHeadMutable(const(Type) type)
574 import dmd.typesem;
575 return dmd.typesem.toHeadMutable(type);
578 Type aliasthisOf(Type type)
580 import dmd.typesem;
581 return dmd.typesem.aliasthisOf(type);
584 Type castMod(Type type, MOD mod)
586 import dmd.typesem;
587 return dmd.typesem.castMod(type, mod);
590 Type addMod(Type type, MOD mod)
592 import dmd.typesem;
593 return dmd.typesem.addMod(type, mod);
596 Type addStorageClass(Type type, StorageClass stc)
598 import dmd.typesem;
599 return dmd.typesem.addStorageClass(type, stc);
602 Type pointerTo(Type type)
604 import dmd.typesem;
605 return dmd.typesem.pointerTo(type);
608 Type referenceTo(Type type)
610 import dmd.typesem;
611 return dmd.typesem.referenceTo(type);
614 /***********************************************************
615 * typinf.d
617 bool genTypeInfo(Expression e, const ref Loc loc, Type torig, Scope* sc)
619 import dmd.typinf;
620 return dmd.typinf.genTypeInfo(e, loc, torig, sc);
623 bool isSpeculativeType(Type t)
625 import dmd.typinf;
626 return dmd.typinf.isSpeculativeType(t);
629 bool builtinTypeInfo(Type t)
631 import dmd.typinf;
632 return dmd.typinf.builtinTypeInfo(t);
635 version (IN_LLVM)
637 /***********************************************************
638 * argtypes_aarch64.d
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 /***********************************************************
662 * argtypes_x86.d
664 TypeTuple toArgTypes_x86(Type t)
666 import dmd.argtypes_x86;
667 return dmd.argtypes_x86.toArgTypes_x86(t);