1 /* d-lang.cc -- Language-dependent hooks for D.
2 Copyright (C) 2006-2023 Free Software Foundation, Inc.
4 GCC is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
9 GCC is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with GCC; see the file COPYING3. If not see
16 <http://www.gnu.org/licenses/>. */
20 #include "coretypes.h"
22 #include "dmd/aggregate.h"
24 #include "dmd/declaration.h"
26 #include "dmd/errors.h"
27 #include "dmd/expression.h"
28 #include "dmd/hdrgen.h"
30 #include "dmd/identifier.h"
32 #include "dmd/mangle.h"
33 #include "dmd/module.h"
34 #include "dmd/mtype.h"
35 #include "dmd/target.h"
36 #include "dmd/template.h"
41 #include "diagnostic.h"
42 #include "fold-const.h"
44 #include "langhooks.h"
45 #include "langhooks-def.h"
48 #include "stringpool.h"
49 #include "stor-layout.h"
52 #include "print-tree.h"
57 #include "d-frontend.h"
60 /* Array of D frontend type/decl nodes. */
61 tree d_global_trees
[DTI_MAX
];
63 /* True if compilation is currently inside the D frontend semantic passes. */
64 bool doing_semantic_analysis_p
= false;
66 /* Options handled by the compiler that are separate from the frontend. */
69 const char *fonly
; /* -fonly=<arg> */
70 const char *multilib
; /* -imultilib <dir> */
71 const char *prefix
; /* -iprefix <dir> */
74 bool deps_skip_system
; /* -MM */
75 const char *deps_filename
; /* -M[M]D */
76 const char *deps_filename_user
; /* -MF <arg> */
77 vec
<const char *> deps_target
; /* -M[QT] <arg> */
78 bool deps_phony
; /* -MP */
80 bool stdinc
; /* -nostdinc */
84 /* List of modules being compiled. */
85 static Modules builtin_modules
;
87 /* The current and global binding level in effect. */
88 struct binding_level
*current_binding_level
;
89 struct binding_level
*global_binding_level
;
91 /* The context to be used for global declarations. */
92 static GTY(()) tree global_context
;
94 /* Array of all global declarations to pass back to the middle-end. */
95 static GTY(()) vec
<tree
, va_gc
> *global_declarations
;
97 /* Support for GCC-style command-line make dependency generation.
98 Adds TARGET to the make dependencies target buffer.
99 QUOTED is true if the string should be quoted. */
102 deps_add_target (const char *target
, bool quoted
)
105 gcc_obstack_init (&buffer
);
109 obstack_grow0 (&buffer
, target
, strlen (target
));
110 d_option
.deps_target
.safe_push ((const char *) obstack_finish (&buffer
));
114 /* Quote characters in target which are significant to Make. */
115 unsigned slashes
= 0;
117 for (const char *p
= target
; *p
!= '\0'; p
++)
128 obstack_1grow (&buffer
, '\\');
129 obstack_1grow (&buffer
, '\\');
133 obstack_1grow (&buffer
, '$');
138 obstack_1grow (&buffer
, '\\');
147 obstack_1grow (&buffer
, *p
);
150 obstack_1grow (&buffer
, '\0');
151 d_option
.deps_target
.safe_push ((const char *) obstack_finish (&buffer
));
154 /* Write STR, with a leading space to BUFFER, updating COLUMN as appropriate.
155 COLMAX is the number of columns to word-wrap at (0 means don't wrap). */
158 deps_write_string (const char *str
, obstack
*buffer
, unsigned &column
,
159 unsigned colmax
= 72)
161 unsigned size
= strlen (str
);
165 if (colmax
&& column
+ size
> colmax
)
167 obstack_grow (buffer
, " \\\n ", 4);
172 obstack_1grow (buffer
, ' ');
178 obstack_grow (buffer
, str
, size
);
181 /* Write out all dependencies of a given MODULE to the specified BUFFER. */
184 deps_write (Module
*module
, obstack
*buffer
)
186 hash_set
<const char *> seen_modules
;
187 vec
<const char *> dependencies
= vNULL
;
190 modlist
.push (module
);
192 vec
<const char *> phonylist
= vNULL
;
195 /* Write out make target module name. */
196 if (d_option
.deps_target
.length ())
198 for (unsigned i
= 0; i
< d_option
.deps_target
.length (); i
++)
199 deps_write_string (d_option
.deps_target
[i
], buffer
, column
);
202 deps_write_string (module
->objfile
.toChars (), buffer
, column
);
204 obstack_1grow (buffer
, ':');
207 /* Search all modules for file dependencies. */
208 while (modlist
.length
> 0)
210 Module
*depmod
= modlist
.pop ();
212 const char *modstr
= depmod
->srcfile
.toChars ();
214 /* Skip modules that have already been looked at. */
215 if (seen_modules
.add (modstr
))
218 dependencies
.safe_push (modstr
);
220 /* Add to list of phony targets if is not being compile. */
221 if (d_option
.deps_phony
&& !depmod
->isRoot ())
222 phonylist
.safe_push (modstr
);
224 /* Add imported files to dependency list. */
225 for (size_t i
= 0; i
< depmod
->contentImportedFiles
.length
; i
++)
227 const char *impstr
= depmod
->contentImportedFiles
[i
];
228 dependencies
.safe_push (impstr
);
229 phonylist
.safe_push (impstr
);
232 /* Search all imports of the module. */
233 for (size_t i
= 0; i
< depmod
->aimports
.length
; i
++)
235 Module
*m
= depmod
->aimports
[i
];
237 /* Ignore compiler-generated modules. */
238 if (m
->ident
== Identifier::idPool ("__main") && m
->parent
== NULL
)
241 /* Don't search system installed modules, this includes
242 object, core.*, std.*, and gcc.* packages. */
243 if (d_option
.deps_skip_system
)
245 if (m
->ident
== Identifier::idPool ("object")
246 && m
->parent
== NULL
)
249 if (m
->md
&& m
->md
->packages
.length
)
251 Identifier
*package
= m
->md
->packages
.ptr
[0];
253 if (package
== Identifier::idPool ("core")
254 || package
== Identifier::idPool ("std")
255 || package
== Identifier::idPool ("gcc"))
264 /* Write out all make dependencies. */
265 for (size_t i
= 0; i
< dependencies
.length (); i
++)
266 deps_write_string (dependencies
[i
], buffer
, column
);
268 obstack_1grow (buffer
, '\n');
270 /* Write out all phony targets. */
271 for (size_t i
= 0; i
< phonylist
.length (); i
++)
273 const char *str
= phonylist
[i
];
274 obstack_1grow (buffer
, '\n');
275 obstack_grow (buffer
, str
, strlen (str
));
276 obstack_grow (buffer
, ":\n", 2);
279 obstack_1grow (buffer
, '\0');
282 /* Implements the lang_hooks.init_options routine for language D.
283 This initializes the global state for the D frontend before calling
284 the option handlers. */
287 d_init_options (unsigned int, cl_decoded_option
*decoded_options
)
289 /* Initialize the D runtime. */
293 /* Set default values. */
296 global
.vendor
= lang_hooks
.name
;
297 global
.params
.argv0
= xstrdup (decoded_options
[0].arg
);
298 global
.params
.errorLimit
= flag_max_errors
;
300 /* Default extern(C++) mangling to C++17. */
301 global
.params
.cplusplus
= CppStdRevisionCpp17
;
303 /* Warnings and deprecations are disabled by default. */
304 global
.params
.useDeprecated
= DIAGNOSTICinform
;
305 global
.params
.warnings
= DIAGNOSTICoff
;
306 global
.params
.messageStyle
= MessageStyle::gnu
;
308 global
.params
.imppath
= d_gc_malloc
<Strings
> ();
309 global
.params
.fileImppath
= d_gc_malloc
<Strings
> ();
311 /* Extra GDC-specific options. */
312 d_option
.fonly
= NULL
;
313 d_option
.multilib
= NULL
;
314 d_option
.prefix
= NULL
;
315 d_option
.deps
= false;
316 d_option
.deps_skip_system
= false;
317 d_option
.deps_filename
= NULL
;
318 d_option
.deps_filename_user
= NULL
;
319 d_option
.deps_target
= vNULL
;
320 d_option
.deps_phony
= false;
321 d_option
.stdinc
= true;
324 /* Implements the lang_hooks.init_options_struct routine for language D.
325 Initializes the options structure OPTS. */
328 d_init_options_struct (gcc_options
*opts
)
331 opts
->x_flag_exceptions
= 1;
333 /* Unlike C, there is no global `errno' variable. */
334 opts
->x_flag_errno_math
= 0;
335 opts
->frontend_set_flag_errno_math
= true;
337 /* D says that signed overflow is precisely defined. */
338 opts
->x_flag_wrapv
= 1;
341 /* Implements the lang_hooks.lang_mask routine for language D.
342 Returns language mask for option parsing. */
345 d_option_lang_mask (void)
350 /* Implements input charset and BOM skipping configuration for
352 static const char *d_input_charset_callback (const char * /*filename*/)
354 /* TODO: The input charset is automatically determined by code in
355 dmd/dmodule.c based on the contents of the file. If this detection
356 logic were factored out and could be reused here, then we would be able
357 to return UTF-16 or UTF-32 as needed here. For now, we return always
358 NULL, which means no conversion is necessary, i.e. the input is assumed
359 to be UTF-8 when diagnostics read this file. */
363 /* Implements the lang_hooks.init routine for language D. */
371 Expression::_init ();
374 /* Diagnostics input init, to enable BOM skipping and
375 input charset conversion. */
376 diagnostic_initialize_input_context (global_dc
,
377 d_input_charset_callback
, true);
380 global_binding_level
= ggc_cleared_alloc
<binding_level
> ();
381 current_binding_level
= global_binding_level
;
383 /* This allows the code in d-builtins.cc to not have to worry about
384 converting (C signed char *) to (D char *) for string arguments of
385 built-in functions. The parameter (signed_char = false) specifies
386 whether char is signed. */
387 build_common_tree_nodes (false);
392 using_eh_for_cleanups ();
394 if (!supports_one_only ())
395 flag_weak_templates
= 0;
397 /* This is the C main, not the D main. */
398 main_identifier_node
= get_identifier ("main");
400 target
._init (global
.params
);
403 /* Insert all library-configured identifiers and import paths. */
404 add_import_paths (d_option
.prefix
, d_option
.multilib
, d_option
.stdinc
);
409 /* Implements the lang_hooks.init_ts routine for language D. */
414 MARK_TS_TYPED (FLOAT_MOD_EXPR
);
415 MARK_TS_TYPED (UNSIGNED_RSHIFT_EXPR
);
418 /* Implements the lang_hooks.handle_option routine for language D.
419 Handles D specific options. Return false if we didn't do anything. */
422 d_handle_option (size_t scode
, const char *arg
, HOST_WIDE_INT value
,
423 int kind ATTRIBUTE_UNUSED
,
424 location_t loc ATTRIBUTE_UNUSED
,
425 const cl_option_handlers
*handlers ATTRIBUTE_UNUSED
)
427 opt_code code
= (opt_code
) scode
;
432 case OPT_fall_instantiations
:
433 global
.params
.allInst
= value
;
437 global
.params
.useAssert
= value
? CHECKENABLEon
: CHECKENABLEoff
;
440 case OPT_fbounds_check
:
441 global
.params
.useArrayBounds
= value
? CHECKENABLEon
: CHECKENABLEoff
;
444 case OPT_fbounds_check_
:
445 global
.params
.useArrayBounds
= (value
== 2) ? CHECKENABLEon
446 : (value
== 1) ? CHECKENABLEsafeonly
: CHECKENABLEoff
;
449 case OPT_fcheckaction_
:
450 global
.params
.checkAction
= (value
== 0) ? CHECKACTION_D
451 : (value
== 1) ? CHECKACTION_halt
: CHECKACTION_context
;
455 global
.params
.debuglevel
= value
? 1 : 0;
459 if (Identifier::isValidIdentifier (CONST_CAST (char *, arg
)))
461 if (!global
.params
.debugids
)
462 global
.params
.debugids
= d_gc_malloc
<Strings
> ();
463 global
.params
.debugids
->push (arg
);
467 error ("bad argument for %<-fdebug%>: %qs", arg
);
471 global
.params
.ddoc
.doOutput
= value
;
475 global
.params
.ddoc
.doOutput
= true;
476 global
.params
.ddoc
.dir
= arg
;
480 global
.params
.ddoc
.doOutput
= true;
481 global
.params
.ddoc
.name
= arg
;
485 global
.params
.ddoc
.files
.push (arg
);
489 global
.params
.betterC
= !value
;
492 case OPT_fdump_c___spec_
:
493 global
.params
.cxxhdr
.doOutput
= true;
494 global
.params
.cxxhdr
.name
= arg
;
497 case OPT_fdump_c___spec_verbose
:
498 global
.params
.cxxhdr
.fullOutput
= true;
501 case OPT_fdump_d_original
:
502 global
.params
.vcg_ast
= value
;
505 case OPT_fexceptions
:
506 global
.params
.useExceptions
= value
;
509 case OPT_fextern_std_
:
512 case CppStdRevisionCpp98
:
513 case CppStdRevisionCpp11
:
514 case CppStdRevisionCpp14
:
515 case CppStdRevisionCpp17
:
516 case CppStdRevisionCpp20
:
517 global
.params
.cplusplus
= (CppStdRevision
) value
;
521 error ("bad argument for %<-fextern-std%>: %qs", arg
);
525 case OPT_fignore_unknown_pragmas
:
526 global
.params
.ignoreUnsupportedPragmas
= value
;
529 case OPT_finvariants
:
530 global
.params
.useInvariants
= value
? CHECKENABLEon
: CHECKENABLEoff
;
534 global
.params
.addMain
= value
;
537 case OPT_fmodule_file_
:
538 global
.params
.modFileAliasStrings
.push (arg
);
539 if (!strchr (arg
, '='))
540 error ("bad argument for %<-fmodule-file%>: %qs", arg
);
543 case OPT_fmoduleinfo
:
544 global
.params
.useModuleInfo
= value
;
548 d_option
.fonly
= arg
;
551 case OPT_fpostconditions
:
552 global
.params
.useOut
= value
? CHECKENABLEon
: CHECKENABLEoff
;
555 case OPT_fpreconditions
:
556 global
.params
.useIn
= value
? CHECKENABLEon
: CHECKENABLEoff
;
559 case OPT_fpreview_all
:
560 global
.params
.ehnogc
= value
;
561 global
.params
.useDIP1000
= FeatureState::enabled
;
562 global
.params
.useDIP1021
= value
;
563 global
.params
.bitfields
= value
;
564 global
.params
.dtorFields
= FeatureState::enabled
;
565 global
.params
.fieldwise
= value
;
566 global
.params
.fixAliasThis
= value
;
567 global
.params
.previewIn
= value
;
568 global
.params
.fix16997
= value
;
569 global
.params
.noSharedAccess
= FeatureState::enabled
;
570 global
.params
.rvalueRefParam
= FeatureState::enabled
;
571 global
.params
.inclusiveInContracts
= value
;
572 global
.params
.systemVariables
= FeatureState::enabled
;
573 global
.params
.fixImmutableConv
= value
;
576 case OPT_fpreview_bitfields
:
577 global
.params
.bitfields
= value
;
580 case OPT_fpreview_dip1000
:
581 global
.params
.useDIP1000
= FeatureState::enabled
;
584 case OPT_fpreview_dip1008
:
585 global
.params
.ehnogc
= value
;
588 case OPT_fpreview_dip1021
:
589 global
.params
.useDIP1021
= value
;
592 case OPT_fpreview_dtorfields
:
593 global
.params
.dtorFields
= FeatureState::enabled
;
596 case OPT_fpreview_fieldwise
:
597 global
.params
.fieldwise
= value
;
600 case OPT_fpreview_fixaliasthis
:
601 global
.params
.fixAliasThis
= value
;
604 case OPT_fpreview_fiximmutableconv
:
605 global
.params
.fixImmutableConv
= value
;
608 case OPT_fpreview_in
:
609 global
.params
.previewIn
= value
;
612 case OPT_fpreview_inclusiveincontracts
:
613 global
.params
.inclusiveInContracts
= value
;
616 case OPT_fpreview_nosharedaccess
:
617 global
.params
.noSharedAccess
= FeatureState::enabled
;
620 case OPT_fpreview_rvaluerefparam
:
621 global
.params
.rvalueRefParam
= FeatureState::enabled
;
624 case OPT_fpreview_systemvariables
:
625 global
.params
.systemVariables
= FeatureState::enabled
;
629 global
.params
.release
= value
;
632 case OPT_frevert_all
:
633 global
.params
.useDIP1000
= FeatureState::disabled
;
634 global
.params
.dtorFields
= FeatureState::disabled
;
635 global
.params
.fix16997
= !value
;
638 case OPT_frevert_dip1000
:
639 global
.params
.useDIP1000
= FeatureState::disabled
;
642 case OPT_frevert_dtorfields
:
643 global
.params
.dtorFields
= FeatureState::disabled
;
646 case OPT_frevert_intpromote
:
647 global
.params
.fix16997
= !value
;
651 global
.params
.useTypeInfo
= value
;
654 case OPT_fsave_mixins_
:
655 global
.params
.mixinOut
.doOutput
= true;
656 global
.params
.mixinOut
.name
= arg
;
657 global
.params
.mixinOut
.buffer
= d_gc_malloc
<OutBuffer
> ();
660 case OPT_fswitch_errors
:
661 global
.params
.useSwitchError
= value
? CHECKENABLEon
: CHECKENABLEoff
;
664 case OPT_ftransition_all
:
665 global
.params
.vfield
= value
;
666 global
.params
.vgc
= value
;
667 global
.params
.vin
= value
;
668 global
.params
.vtls
= value
;
671 case OPT_ftransition_field
:
672 global
.params
.vfield
= value
;
675 case OPT_ftransition_in
:
676 global
.params
.vin
= value
;
679 case OPT_ftransition_nogc
:
680 global
.params
.vgc
= value
;
683 case OPT_ftransition_templates
:
684 global
.params
.vtemplates
= value
;
687 case OPT_ftransition_tls
:
688 global
.params
.vtls
= value
;
692 global
.params
.useUnitTests
= value
;
696 if (Identifier::isValidIdentifier (CONST_CAST (char *, arg
)))
698 if (!global
.params
.versionids
)
699 global
.params
.versionids
= d_gc_malloc
<Strings
> ();
700 global
.params
.versionids
->push (arg
);
704 error ("bad argument for %<-fversion%>: %qs", arg
);
708 global
.params
.dihdr
.doOutput
= true;
712 global
.params
.dihdr
.doOutput
= true;
713 global
.params
.dihdr
.dir
= arg
;
717 global
.params
.dihdr
.doOutput
= true;
718 global
.params
.dihdr
.name
= arg
;
722 d_option
.multilib
= arg
;
726 d_option
.prefix
= arg
;
730 global
.params
.imppath
->push (arg
);
734 global
.params
.fileImppath
->push (arg
);
738 d_option
.deps_skip_system
= true;
742 d_option
.deps
= true;
746 d_option
.deps_skip_system
= true;
750 d_option
.deps
= true;
751 d_option
.deps_filename
= arg
;
755 /* If specified multiple times, last one wins. */
756 d_option
.deps_filename_user
= arg
;
760 d_option
.deps_phony
= true;
764 deps_add_target (arg
, true);
768 deps_add_target (arg
, false);
772 d_option
.stdinc
= false;
776 global
.params
.verbose
= value
;
781 global
.params
.warnings
= DIAGNOSTICinform
;
784 case OPT_Wdeprecated
:
785 global
.params
.useDeprecated
= value
? DIAGNOSTICinform
: DIAGNOSTICoff
;
790 global
.params
.warnings
= DIAGNOSTICerror
;
793 case OPT_Wspeculative
:
795 global
.params
.showGaggedErrors
= 1;
799 global
.params
.json
.name
= arg
;
803 global
.params
.json
.doOutput
= true;
810 D_handle_option_auto (&global_options
, &global_options_set
,
812 d_option_lang_mask (), kind
,
813 loc
, handlers
, global_dc
);
818 /* Implements the lang_hooks.post_options routine for language D.
819 Deal with any options that imply the turning on/off of features.
820 FN is the main input filename passed on the command line. */
823 d_post_options (const char ** fn
)
825 /* Verify the input file name. */
826 const char *filename
= *fn
;
827 if (!filename
|| strcmp (filename
, "-") == 0)
830 /* The front end considers the first input file to be the main one. */
833 /* Release mode doesn't turn off bounds checking for safe functions. */
834 if (global
.params
.useArrayBounds
== CHECKENABLEdefault
)
836 global
.params
.useArrayBounds
= global
.params
.release
837 ? CHECKENABLEsafeonly
: CHECKENABLEon
;
840 /* Assert code is generated if unittests are being compiled also, even if
841 release mode is turned on. */
842 if (global
.params
.useAssert
== CHECKENABLEdefault
)
844 if (global
.params
.useUnitTests
|| !global
.params
.release
)
845 global
.params
.useAssert
= CHECKENABLEon
;
847 global
.params
.useAssert
= CHECKENABLEoff
;
850 /* Checks for switches without a default are turned off in release mode. */
851 if (global
.params
.useSwitchError
== CHECKENABLEdefault
)
853 global
.params
.useSwitchError
= global
.params
.release
854 ? CHECKENABLEoff
: CHECKENABLEon
;
857 /* Contracts are turned off in release mode. */
858 if (global
.params
.useInvariants
== CHECKENABLEdefault
)
860 global
.params
.useInvariants
= global
.params
.release
861 ? CHECKENABLEoff
: CHECKENABLEon
;
864 if (global
.params
.useIn
== CHECKENABLEdefault
)
866 global
.params
.useIn
= global
.params
.release
867 ? CHECKENABLEoff
: CHECKENABLEon
;
870 if (global
.params
.useOut
== CHECKENABLEdefault
)
872 global
.params
.useOut
= global
.params
.release
873 ? CHECKENABLEoff
: CHECKENABLEon
;
876 /* When not linking against D runtime, turn off all code generation that
877 would otherwise reference it. */
878 if (global
.params
.betterC
)
880 if (!OPTION_SET_P (flag_moduleinfo
))
881 global
.params
.useModuleInfo
= false;
883 /* Ensure that the front-end options are in sync with the `-frtti' and
884 `-fexceptions' flags. */
885 if (!OPTION_SET_P (flag_rtti
))
887 global
.params
.useTypeInfo
= false;
891 if (!OPTION_SET_P (flag_exceptions
))
893 global
.params
.useExceptions
= false;
894 flag_exceptions
= false;
897 global
.params
.checkAction
= CHECKACTION_C
;
900 /* Enabling DIP1021 implies DIP1000. */
901 if (global
.params
.useDIP1021
)
902 global
.params
.useDIP1000
= FeatureState::enabled
;
904 /* Keep in sync with existing -fbounds-check flag. */
905 flag_bounds_check
= (global
.params
.useArrayBounds
== CHECKENABLEon
);
907 /* Turn off partitioning unless it was explicitly requested, as it doesn't
908 work with D exception chaining, where EH handler uses LSDA to determine
909 whether two thrown exception are in the same context. */
910 if (!OPTION_SET_P (flag_reorder_blocks_and_partition
))
911 global_options
.x_flag_reorder_blocks_and_partition
= 0;
913 /* Error about use of deprecated features. */
914 if (global
.params
.useDeprecated
== DIAGNOSTICinform
915 && global
.params
.warnings
== DIAGNOSTICerror
)
916 global
.params
.useDeprecated
= DIAGNOSTICerror
;
918 /* Make -fmax-errors visible to frontend's diagnostic machinery. */
919 if (OPTION_SET_P (flag_max_errors
))
920 global
.params
.errorLimit
= flag_max_errors
;
922 if (flag_excess_precision
== EXCESS_PRECISION_DEFAULT
)
923 flag_excess_precision
= EXCESS_PRECISION_STANDARD
;
925 global
.params
.useInline
= flag_inline_functions
;
926 global
.params
.showColumns
= flag_show_column
;
927 global
.params
.printErrorContext
= flag_diagnostics_show_caret
;
929 /* Keep the front-end location type in sync with params. */
930 Loc::set (global
.params
.showColumns
, global
.params
.messageStyle
);
932 if (global
.params
.useInline
)
933 global
.params
.dihdr
.fullOutput
= true;
935 global
.params
.obj
= !flag_syntax_only
;
937 /* Add in versions given on the command line. */
938 if (global
.params
.versionids
)
940 for (size_t i
= 0; i
< global
.params
.versionids
->length
; i
++)
942 const char *s
= (*global
.params
.versionids
)[i
];
943 VersionCondition::addGlobalIdent (s
);
947 if (global
.params
.debugids
)
949 for (size_t i
= 0; i
< global
.params
.debugids
->length
; i
++)
951 const char *s
= (*global
.params
.debugids
)[i
];
952 DebugCondition::addGlobalIdent (s
);
956 if (warn_return_type
== -1)
957 warn_return_type
= 0;
962 /* Add the module M to the list of modules that may declare GCC builtins.
963 These are scanned after first semantic and before codegen passes.
964 See d_maybe_set_builtin() for the implementation. */
967 d_add_builtin_module (Module
*m
)
969 builtin_modules
.push (m
);
972 /* Implements the lang_hooks.parse_file routine for language D. */
977 if (global
.params
.verbose
)
979 message ("binary %s", global
.params
.argv0
.ptr
);
980 message ("version %s", global
.versionChars ());
982 if (global
.versionids
)
985 gcc_obstack_init (&buffer
);
986 obstack_grow (&buffer
, "predefs ", 9);
987 for (size_t i
= 0; i
< global
.versionids
->length
; i
++)
989 Identifier
*id
= (*global
.versionids
)[i
];
990 const char *str
= id
->toChars ();
991 obstack_1grow (&buffer
, ' ');
992 obstack_grow (&buffer
, str
, strlen (str
));
995 obstack_1grow (&buffer
, '\0');
996 message ("%s", (char *) obstack_finish (&buffer
));
1000 /* Start the main input file, if the debug writer wants it. */
1001 if (debug_hooks
->start_end_main_source_file
)
1002 debug_hooks
->start_source_file (0, main_input_filename
);
1004 /* Create Module's for all sources we will load. */
1006 modules
.reserve (num_in_fnames
);
1008 /* In this mode, the first file name is supposed to be a duplicate
1009 of one of the input files. */
1010 if (d_option
.fonly
&& strcmp (d_option
.fonly
, main_input_filename
) != 0)
1011 error ("%<-fonly=%> argument is different from first input file name");
1013 for (size_t i
= 0; i
< num_in_fnames
; i
++)
1015 if (strcmp (in_fnames
[i
], "-") == 0)
1017 /* Load the entire contents of stdin into memory. 8 kilobytes should
1018 be a good enough initial size, but double on each iteration.
1019 16 bytes are added for the final '\n' and 15 bytes of padding. */
1020 ssize_t size
= 8 * 1024;
1021 uchar
*buffer
= XNEWVEC (uchar
, size
+ 16);
1025 while ((count
= read (STDIN_FILENO
, buffer
+ len
, size
- len
)) > 0)
1031 buffer
= XRESIZEVEC (uchar
, buffer
, size
+ 16);
1037 error (Loc ("stdin", 0, 0), "%s", xstrerror (errno
));
1042 /* Handling stdin, generate a unique name for the module. */
1043 Module
*m
= Module::create (in_fnames
[i
],
1044 Identifier::idPool ("__stdin"),
1045 global
.params
.ddoc
.doOutput
,
1046 global
.params
.dihdr
.doOutput
);
1049 /* Zero the padding past the end of the buffer so the D lexer has a
1050 sentinel. The lexer only reads up to 4 bytes at a time. */
1051 memset (buffer
+ len
, '\0', 16);
1053 /* Overwrite the source file for the module, the one created by
1054 Module::create would have a forced a `.d' suffix. */
1055 m
->src
.length
= len
;
1056 m
->src
.ptr
= buffer
;
1060 /* Handling a D source file, strip off the path and extension. */
1061 const char *basename
= FileName::name (in_fnames
[i
]);
1062 const char *name
= FileName::removeExt (basename
);
1064 Module
*m
= Module::create (in_fnames
[i
], Identifier::idPool (name
),
1065 global
.params
.ddoc
.doOutput
,
1066 global
.params
.dihdr
.doOutput
);
1068 FileName::free (name
);
1072 /* Read all D source files. */
1073 for (size_t i
= 0; i
< modules
.length
; i
++)
1075 Module
*m
= modules
[i
];
1079 /* Parse all D source files. */
1080 for (size_t i
= 0; i
< modules
.length
; i
++)
1082 Module
*m
= modules
[i
];
1084 if (global
.params
.verbose
)
1085 message ("parse %s", m
->toChars ());
1087 if (!Module::rootModule
)
1088 Module::rootModule
= m
;
1090 m
->importedFrom
= m
;
1093 if (m
->filetype
== FileType::ddoc
)
1096 /* Remove M from list of modules. */
1102 /* Load the module containing D main. */
1103 Module
*main_module
= NULL
;
1104 if (global
.params
.addMain
)
1106 unsigned errors
= global
.startGagging ();
1107 main_module
= Module::load (Loc (), NULL
, Identifier::idPool ("__main"));
1109 if (!global
.endGagging (errors
))
1111 main_module
->importedFrom
= main_module
;
1112 modules
.push (main_module
);
1116 /* If an error occurs later during compilation, remember that we generated
1117 the headers, so that they can be removed before exit. */
1118 bool dump_headers
= false;
1123 if (global
.params
.dihdr
.doOutput
)
1125 /* Generate 'header' import files. Since 'header' import files must be
1126 independent of command line switches and what else is imported, they
1127 are generated before any semantic analysis. */
1128 for (size_t i
= 0; i
< modules
.length
; i
++)
1130 Module
*m
= modules
[i
];
1131 if (m
->filetype
== FileType::dhdr
1132 || (d_option
.fonly
&& m
!= Module::rootModule
))
1135 if (global
.params
.verbose
)
1136 message ("import %s", m
->toChars ());
1141 dump_headers
= true;
1147 /* Load all unconditional imports for better symbol resolving. */
1148 for (size_t i
= 0; i
< modules
.length
; i
++)
1150 Module
*m
= modules
[i
];
1152 if (global
.params
.verbose
)
1153 message ("importall %s", m
->toChars ());
1155 m
->importAll (NULL
);
1161 /* Do semantic analysis. */
1162 doing_semantic_analysis_p
= true;
1164 for (size_t i
= 0; i
< modules
.length
; i
++)
1166 Module
*m
= modules
[i
];
1168 /* If this is the `__main` module, check that `D main` hasn't already
1169 been declared in user code before running semantic on it. */
1170 if (m
== main_module
&& global
.hasMainFunction
)
1176 if (global
.params
.verbose
)
1177 message ("semantic %s", m
->toChars ());
1179 dsymbolSemantic (m
, NULL
);
1182 /* Do deferred semantic analysis. */
1183 Module::runDeferredSemantic ();
1185 if (Module::deferred
.length
)
1187 for (size_t i
= 0; i
< Module::deferred
.length
; i
++)
1189 Dsymbol
*sd
= Module::deferred
[i
];
1190 error_at (make_location_t (sd
->loc
),
1191 "unable to resolve forward reference in definition");
1195 /* Process all built-in modules or functions now for CTFE. */
1196 while (builtin_modules
.length
!= 0)
1198 Module
*m
= builtin_modules
.pop ();
1199 d_maybe_set_builtin (m
);
1202 /* Do pass 2 semantic analysis. */
1203 for (size_t i
= 0; i
< modules
.length
; i
++)
1205 Module
*m
= modules
[i
];
1207 if (global
.params
.verbose
)
1208 message ("semantic2 %s", m
->toChars ());
1210 semantic2 (m
, NULL
);
1213 Module::runDeferredSemantic2 ();
1218 /* Do pass 3 semantic analysis. */
1219 for (size_t i
= 0; i
< modules
.length
; i
++)
1221 Module
*m
= modules
[i
];
1223 if (global
.params
.verbose
)
1224 message ("semantic3 %s", m
->toChars ());
1226 semantic3 (m
, NULL
);
1229 Module::runDeferredSemantic3 ();
1231 /* Check again, incase semantic3 pass loaded any more modules. */
1232 while (builtin_modules
.length
!= 0)
1234 Module
*m
= builtin_modules
.pop ();
1235 d_maybe_set_builtin (m
);
1238 /* Do not attempt to generate output files if errors or warnings occurred. */
1239 if (global
.errors
|| global
.warnings
)
1242 /* Generate output files. */
1243 doing_semantic_analysis_p
= false;
1245 if (Module::rootModule
)
1247 /* Declare the name of the root module as the first global name in order
1248 to make the middle-end fully deterministic. */
1250 mangleToBuffer (Module::rootModule
, &buf
);
1251 first_global_object_name
= buf
.extractChars ();
1254 /* Make dependencies. */
1260 gcc_obstack_init (&buffer
);
1262 for (size_t i
= 0; i
< modules
.length
; i
++)
1263 deps_write (modules
[i
], &buffer
);
1265 /* -MF <arg> overrides -M[M]D. */
1266 if (d_option
.deps_filename_user
)
1267 d_option
.deps_filename
= d_option
.deps_filename_user
;
1269 if (d_option
.deps_filename
)
1271 deps_stream
= fopen (d_option
.deps_filename
, "w");
1274 fatal_error (input_location
, "opening dependency file %s: %m",
1275 d_option
.deps_filename
);
1280 deps_stream
= stdout
;
1282 fprintf (deps_stream
, "%s", (char *) obstack_finish (&buffer
));
1284 if (deps_stream
!= stdout
1285 && (ferror (deps_stream
) || fclose (deps_stream
)))
1287 fatal_error (input_location
, "closing dependency file %s: %m",
1288 d_option
.deps_filename
);
1292 if (global
.params
.vtemplates
)
1293 printTemplateStats ();
1295 /* Generate JSON files. */
1296 if (global
.params
.json
.doOutput
)
1299 json_generate (&buf
, &modules
);
1301 const char *name
= global
.params
.json
.name
.ptr
;
1304 if (name
&& (name
[0] != '-' || name
[1] != '\0'))
1307 = FileName::defaultExt (name
, json_ext
.ptr
);
1308 json_stream
= fopen (nameext
, "w");
1311 fatal_error (input_location
, "opening json file %s: %m", nameext
);
1316 json_stream
= stdout
;
1318 fprintf (json_stream
, "%s", buf
.peekChars ());
1320 if (json_stream
!= stdout
1321 && (ferror (json_stream
) || fclose (json_stream
)))
1322 fatal_error (input_location
, "closing json file %s: %m", name
);
1325 /* Generate Ddoc files. */
1326 if (global
.params
.ddoc
.doOutput
&& !global
.errors
&& !errorcount
)
1328 for (size_t i
= 0; i
< modules
.length
; i
++)
1330 Module
*m
= modules
[i
];
1335 /* Handle -fdump-d-original. */
1336 if (global
.params
.vcg_ast
)
1338 for (size_t i
= 0; i
< modules
.length
; i
++)
1340 Module
*m
= modules
[i
];
1344 moduleToBuffer (&buf
, m
);
1345 message ("%s", buf
.peekChars ());
1349 /* Generate C++ header files. */
1350 if (global
.params
.cxxhdr
.doOutput
)
1351 genCppHdrFiles (modules
);
1356 for (size_t i
= 0; i
< modules
.length
; i
++)
1358 Module
*m
= modules
[i
];
1360 /* Skip generating code for header files, or when the module wasn't
1361 specified by `-fonly=`. */
1362 if ((m
->filetype
== FileType::dhdr
&& m
!= main_module
)
1363 || (d_option
.fonly
&& m
!= Module::rootModule
))
1366 if (global
.params
.verbose
)
1367 message ("code %s", m
->toChars ());
1369 if (!flag_syntax_only
)
1370 build_decl_tree (m
);
1373 /* And end the main input file, if the debug writer wants it. */
1374 if (debug_hooks
->start_end_main_source_file
)
1375 debug_hooks
->end_source_file (0);
1378 /* Add the D frontend error count to the GCC error count to correctly
1379 exit with an error status. */
1380 errorcount
+= (global
.errors
+ global
.warnings
);
1382 /* We want to write the mixin expansion file also on error. */
1383 if (global
.params
.mixinOut
.doOutput
)
1385 FILE *mixin_stream
= fopen (global
.params
.mixinOut
.name
.ptr
, "w");
1389 OutBuffer
*buf
= global
.params
.mixinOut
.buffer
;
1390 fprintf (mixin_stream
, "%s", buf
->peekChars ());
1392 if (ferror (mixin_stream
) || fclose (mixin_stream
))
1393 fatal_error (input_location
, "closing mixin file %s: %m",
1394 global
.params
.mixinOut
.name
.ptr
);
1398 fatal_error (input_location
, "opening mixin file %s: %m",
1399 global
.params
.mixinOut
.name
.ptr
);
1403 /* Remove generated .di files on error. */
1404 if (errorcount
&& dump_headers
)
1406 for (size_t i
= 0; i
< modules
.length
; i
++)
1408 Module
*m
= modules
[i
];
1409 if (m
->filetype
== FileType::dhdr
1410 || (d_option
.fonly
&& m
!= Module::rootModule
))
1413 remove (m
->hdrfile
.toChars ());
1417 /* Write out globals. */
1418 d_finish_compilation (vec_safe_address (global_declarations
),
1419 vec_safe_length (global_declarations
));
1422 /* Implements the lang_hooks.types.type_for_mode routine for language D. */
1425 d_type_for_mode (machine_mode mode
, int unsignedp
)
1428 return unsignedp
? d_ubyte_type
: d_byte_type
;
1431 return unsignedp
? d_ushort_type
: d_short_type
;
1434 return unsignedp
? d_uint_type
: d_int_type
;
1437 return unsignedp
? d_ulong_type
: d_long_type
;
1439 if (mode
== TYPE_MODE (d_cent_type
))
1440 return unsignedp
? d_ucent_type
: d_cent_type
;
1442 if (mode
== TYPE_MODE (float_type_node
))
1443 return float_type_node
;
1445 if (mode
== TYPE_MODE (double_type_node
))
1446 return double_type_node
;
1448 if (mode
== TYPE_MODE (long_double_type_node
))
1449 return long_double_type_node
;
1451 if (mode
== TYPE_MODE (build_pointer_type (char8_type_node
)))
1452 return build_pointer_type (char8_type_node
);
1454 if (mode
== TYPE_MODE (build_pointer_type (d_int_type
)))
1455 return build_pointer_type (d_int_type
);
1457 for (int i
= 0; i
< NUM_INT_N_ENTS
; i
++)
1459 if (int_n_enabled_p
[i
] && mode
== int_n_data
[i
].m
)
1462 return int_n_trees
[i
].unsigned_type
;
1464 return int_n_trees
[i
].signed_type
;
1468 if (COMPLEX_MODE_P (mode
))
1470 machine_mode inner_mode
;
1473 if (mode
== TYPE_MODE (complex_float_type_node
))
1474 return complex_float_type_node
;
1475 if (mode
== TYPE_MODE (complex_double_type_node
))
1476 return complex_double_type_node
;
1477 if (mode
== TYPE_MODE (complex_long_double_type_node
))
1478 return complex_long_double_type_node
;
1480 inner_mode
= (machine_mode
) GET_MODE_INNER (mode
);
1481 inner_type
= d_type_for_mode (inner_mode
, unsignedp
);
1482 if (inner_type
!= NULL_TREE
)
1483 return build_complex_type (inner_type
);
1485 else if (VECTOR_MODE_P (mode
))
1487 machine_mode inner_mode
= (machine_mode
) GET_MODE_INNER (mode
);
1488 tree inner_type
= d_type_for_mode (inner_mode
, unsignedp
);
1489 if (inner_type
!= NULL_TREE
)
1490 return build_vector_type_for_mode (inner_type
, mode
);
1496 /* Implements the lang_hooks.types.type_for_size routine for language D. */
1499 d_type_for_size (unsigned bits
, int unsignedp
)
1501 if (bits
<= TYPE_PRECISION (d_byte_type
))
1502 return unsignedp
? d_ubyte_type
: d_byte_type
;
1504 if (bits
<= TYPE_PRECISION (d_short_type
))
1505 return unsignedp
? d_ushort_type
: d_short_type
;
1507 if (bits
<= TYPE_PRECISION (d_int_type
))
1508 return unsignedp
? d_uint_type
: d_int_type
;
1510 if (bits
<= TYPE_PRECISION (d_long_type
))
1511 return unsignedp
? d_ulong_type
: d_long_type
;
1513 if (bits
<= TYPE_PRECISION (d_cent_type
))
1514 return unsignedp
? d_ucent_type
: d_cent_type
;
1516 for (int i
= 0; i
< NUM_INT_N_ENTS
; i
++)
1518 if (int_n_enabled_p
[i
] && bits
== int_n_data
[i
].bitsize
)
1521 return int_n_trees
[i
].unsigned_type
;
1523 return int_n_trees
[i
].signed_type
;
1530 /* Implements the lang_hooks.types.type_promotes_to routine for language D. */
1533 d_type_promotes_to (tree type
)
1535 /* Promotions are only applied on unnamed function arguments for declarations
1536 with `extern(C)' or `extern(C++)' linkage. */
1537 if (cfun
&& DECL_LANG_FRONTEND (cfun
->decl
)
1538 && DECL_LANG_FRONTEND (cfun
->decl
)->resolvedLinkage () != LINK::d
)
1540 /* In [type/integer-promotions], integer promotions are conversions of the
1552 If an enum has as a base type one of the types in the left column, it
1553 is converted to the type in the right column. */
1554 if (TREE_CODE (type
) == ENUMERAL_TYPE
&& ENUM_IS_SCOPED (type
))
1555 type
= TREE_TYPE (type
);
1557 type
= TYPE_MAIN_VARIANT (type
);
1559 /* Check for promotions of target-defined types first. */
1560 tree promoted_type
= targetm
.promoted_type (type
);
1562 return promoted_type
;
1564 if (TREE_CODE (type
) == BOOLEAN_TYPE
)
1567 if (INTEGRAL_TYPE_P (type
))
1569 if (type
== d_byte_type
|| type
== d_ubyte_type
1570 || type
== d_short_type
|| type
== d_ushort_type
1571 || type
== char8_type_node
|| type
== char16_type_node
)
1574 if (type
== char32_type_node
)
1577 if (TYPE_PRECISION (type
) < TYPE_PRECISION (d_int_type
))
1581 /* Float arguments are converted to doubles. */
1582 if (type
== float_type_node
)
1583 return double_type_node
;
1585 if (type
== ifloat_type_node
)
1586 return idouble_type_node
;
1592 /* Implements the lang_hooks.decls.global_bindings_p routine for language D.
1593 Return true if we are in the global binding level. */
1596 d_global_bindings_p (void)
1598 return (current_binding_level
== global_binding_level
);
1601 /* Return global_context, but create it first if need be. */
1604 get_global_context (void)
1606 if (!global_context
)
1608 global_context
= build_translation_unit_decl (NULL_TREE
);
1609 debug_hooks
->register_main_translation_unit (global_context
);
1612 return global_context
;
1615 /* Implements the lang_hooks.decls.pushdecl routine for language D.
1616 Record DECL as belonging to the current lexical scope. */
1619 d_pushdecl (tree decl
)
1621 /* Set the context of the decl. If current_function_decl did not help in
1622 determining the context, use global scope. */
1623 if (!DECL_CONTEXT (decl
))
1625 if (current_function_decl
)
1626 DECL_CONTEXT (decl
) = current_function_decl
;
1628 DECL_CONTEXT (decl
) = get_global_context ();
1631 /* Put decls on list in reverse order. */
1632 if (TREE_STATIC (decl
) || d_global_bindings_p ())
1633 vec_safe_push (global_declarations
, decl
);
1636 TREE_CHAIN (decl
) = current_binding_level
->names
;
1637 current_binding_level
->names
= decl
;
1643 /* Implements the lang_hooks.decls.getdecls routine for language D.
1644 Return the list of declarations of the current level. */
1649 if (current_binding_level
)
1650 return current_binding_level
->names
;
1656 /* Implements the lang_hooks.get_alias_set routine for language D.
1657 Get the alias set corresponding to type or expression T.
1658 Return -1 if we don't do anything special. */
1660 static alias_set_type
1661 d_get_alias_set (tree
)
1663 /* For now in D, assume everything aliases everything else, until we define
1664 some solid rules backed by a specification. There are also some parts
1665 of code generation routines that don't adhere to C alias rules, such as
1666 build_vconvert. In any case, a lot of user code already assumes there
1667 is no strict aliasing and will break if we were to change that. */
1671 /* Implements the lang_hooks.types_compatible_p routine for language D.
1672 Compares two types for equivalence in the D programming language.
1673 This routine should only return 1 if it is sure, even though the frontend
1674 should have already ensured that all types are compatible before handing
1675 over the parsed ASTs to the code generator. */
1678 d_types_compatible_p (tree x
, tree y
)
1680 Type
*tx
= TYPE_LANG_FRONTEND (x
);
1681 Type
*ty
= TYPE_LANG_FRONTEND (y
);
1683 /* Try validating the types in the frontend. */
1684 if (tx
!= NULL
&& ty
!= NULL
)
1686 /* Types are equivalent. */
1687 if (same_type_p (tx
, ty
))
1690 /* Type system allows implicit conversion between. */
1691 if (tx
->implicitConvTo (ty
) != MATCH::nomatch
1692 || ty
->implicitConvTo (tx
) != MATCH::nomatch
)
1696 /* Fallback on using type flags for comparison. E.g: all dynamic arrays
1697 are distinct types in D, but are VIEW_CONVERT compatible. */
1698 if (TREE_CODE (x
) == RECORD_TYPE
&& TREE_CODE (y
) == RECORD_TYPE
)
1700 if (TYPE_DYNAMIC_ARRAY (x
) && TYPE_DYNAMIC_ARRAY (y
))
1703 if (TYPE_DELEGATE (x
) && TYPE_DELEGATE (y
))
1706 if (TYPE_ASSOCIATIVE_ARRAY (x
) && TYPE_ASSOCIATIVE_ARRAY (y
))
1713 /* Implements the lang_hooks.finish_incomplete_decl routine for language D. */
1716 d_finish_incomplete_decl (tree decl
)
1720 /* D allows zero-length declarations. Such a declaration ends up with
1721 DECL_SIZE (t) == NULL_TREE which is what the back-end function
1722 assembler_variable checks. This could change in later versions, or
1723 maybe all of these variables should be aliased to one symbol. */
1724 if (DECL_SIZE (decl
) == 0)
1726 DECL_SIZE (decl
) = bitsize_zero_node
;
1727 DECL_SIZE_UNIT (decl
) = size_zero_node
;
1732 /* Implements the lang_hooks.types.classify_record routine for language D.
1733 Return the true debug type for TYPE. */
1735 static classify_record
1736 d_classify_record (tree type
)
1738 Type
*t
= TYPE_LANG_FRONTEND (type
);
1739 TypeClass
*tc
= t
? t
->isTypeClass () : NULL
;
1743 /* extern(C++) interfaces get emitted as classes. */
1744 if (tc
->sym
->isInterfaceDeclaration ()
1745 && !tc
->sym
->isCPPinterface ())
1746 return RECORD_IS_INTERFACE
;
1748 return RECORD_IS_CLASS
;
1751 return RECORD_IS_STRUCT
;
1754 /* Implements the lang_hooks.tree_size routine for language D.
1755 Determine the size of our tcc_constant or tcc_exceptional nodes. */
1758 d_tree_size (tree_code code
)
1762 case FUNCFRAME_INFO
:
1763 return sizeof (tree_frame_info
);
1770 /* Implements the lang_hooks.print_xnode routine for language D. */
1773 d_print_xnode (FILE *file
, tree node
, int indent
)
1775 switch (TREE_CODE (node
))
1777 case FUNCFRAME_INFO
:
1778 print_node (file
, "frame_type", FRAMEINFO_TYPE (node
), indent
+ 4);
1786 /* Return which tree structure is used by NODE, or TS_D_GENERIC if NODE
1787 is one of the language-independent trees. */
1789 d_tree_node_structure_enum
1790 d_tree_node_structure (lang_tree_node
*t
)
1792 switch (TREE_CODE (&t
->generic
))
1794 case IDENTIFIER_NODE
:
1795 return TS_D_IDENTIFIER
;
1797 case FUNCFRAME_INFO
:
1798 return TS_D_FRAMEINFO
;
1801 return TS_D_GENERIC
;
1805 /* Allocate and return a lang specific structure for the frontend type. */
1808 build_lang_type (Type
*t
)
1810 struct lang_type
*lt
= ggc_cleared_alloc
<struct lang_type
> ();
1815 /* Allocate and return a lang specific structure for the frontend decl. */
1818 build_lang_decl (Declaration
*d
)
1820 /* For compiler generated run-time typeinfo, a lang_decl is allocated even if
1821 there's no associated frontend symbol to refer to (yet). If the symbol
1822 appears later in the compilation, then the slot will be re-used. */
1824 return ggc_cleared_alloc
<struct lang_decl
> ();
1826 struct lang_decl
*ld
= (d
->csym
) ? DECL_LANG_SPECIFIC (d
->csym
) : NULL
;
1828 ld
= ggc_cleared_alloc
<struct lang_decl
> ();
1830 if (ld
->decl
== NULL
)
1836 /* Implements the lang_hooks.dup_lang_specific_decl routine for language D.
1837 Replace the DECL_LANG_SPECIFIC field of NODE with a copy. */
1840 d_dup_lang_specific_decl (tree node
)
1842 if (!DECL_LANG_SPECIFIC (node
))
1845 struct lang_decl
*ld
= ggc_alloc
<struct lang_decl
> ();
1846 memcpy (ld
, DECL_LANG_SPECIFIC (node
), sizeof (struct lang_decl
));
1847 DECL_LANG_SPECIFIC (node
) = ld
;
1850 /* This preserves trees we create from the garbage collector. */
1852 static GTY(()) tree d_keep_list
= NULL_TREE
;
1857 d_keep_list
= tree_cons (NULL_TREE
, t
, d_keep_list
);
1860 /* Implements the lang_hooks.eh_personality routine for language D.
1861 Return the GDC personality function decl. */
1863 static GTY(()) tree d_eh_personality_decl
;
1866 d_eh_personality (void)
1868 if (!d_eh_personality_decl
)
1869 d_eh_personality_decl
= build_personality_function ("gdc");
1871 return d_eh_personality_decl
;
1874 /* Implements the lang_hooks.eh_runtime_type routine for language D. */
1877 d_build_eh_runtime_type (tree type
)
1879 Type
*t
= TYPE_LANG_FRONTEND (type
);
1880 gcc_assert (t
!= NULL
);
1881 t
= t
->toBasetype ();
1883 ClassDeclaration
*cd
= t
->isTypeClass ()->sym
;
1886 if (cd
->isCPPclass ())
1887 decl
= get_cpp_typeinfo_decl (cd
);
1889 decl
= get_classinfo_decl (cd
);
1891 return convert (ptr_type_node
, build_address (decl
));
1894 /* Implements the lang_hooks.enum_underlying_base_type routine for language D.
1895 Returns the underlying type of the given enumeration TYPE. */
1898 d_enum_underlying_base_type (const_tree type
)
1900 gcc_assert (TREE_CODE (type
) == ENUMERAL_TYPE
);
1901 return TREE_TYPE (type
);
1904 /* Get a value for the SARIF v2.1.0 "artifact.sourceLanguage" property,
1905 based on the list in SARIF v2.1.0 Appendix J. */
1908 d_get_sarif_source_language (const char *)
1913 /* Definitions for our language-specific hooks. */
1915 #undef LANG_HOOKS_NAME
1916 #undef LANG_HOOKS_INIT
1917 #undef LANG_HOOKS_INIT_TS
1918 #undef LANG_HOOKS_INIT_OPTIONS
1919 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1920 #undef LANG_HOOKS_OPTION_LANG_MASK
1921 #undef LANG_HOOKS_HANDLE_OPTION
1922 #undef LANG_HOOKS_POST_OPTIONS
1923 #undef LANG_HOOKS_PARSE_FILE
1924 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1925 #undef LANG_HOOKS_ATTRIBUTE_TABLE
1926 #undef LANG_HOOKS_GET_ALIAS_SET
1927 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1928 #undef LANG_HOOKS_BUILTIN_FUNCTION
1929 #undef LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE
1930 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1931 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
1932 #undef LANG_HOOKS_GIMPLIFY_EXPR
1933 #undef LANG_HOOKS_CLASSIFY_RECORD
1934 #undef LANG_HOOKS_TREE_SIZE
1935 #undef LANG_HOOKS_PRINT_XNODE
1936 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
1937 #undef LANG_HOOKS_EH_PERSONALITY
1938 #undef LANG_HOOKS_EH_RUNTIME_TYPE
1939 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
1940 #undef LANG_HOOKS_PUSHDECL
1941 #undef LANG_HOOKS_GETDECLS
1942 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1943 #undef LANG_HOOKS_TYPE_FOR_MODE
1944 #undef LANG_HOOKS_TYPE_FOR_SIZE
1945 #undef LANG_HOOKS_TYPE_PROMOTES_TO
1946 #undef LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE
1948 #define LANG_HOOKS_NAME "GNU D"
1949 #define LANG_HOOKS_INIT d_init
1950 #define LANG_HOOKS_INIT_TS d_init_ts
1951 #define LANG_HOOKS_INIT_OPTIONS d_init_options
1952 #define LANG_HOOKS_INIT_OPTIONS_STRUCT d_init_options_struct
1953 #define LANG_HOOKS_OPTION_LANG_MASK d_option_lang_mask
1954 #define LANG_HOOKS_HANDLE_OPTION d_handle_option
1955 #define LANG_HOOKS_POST_OPTIONS d_post_options
1956 #define LANG_HOOKS_PARSE_FILE d_parse_file
1957 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE d_langhook_common_attribute_table
1958 #define LANG_HOOKS_ATTRIBUTE_TABLE d_langhook_attribute_table
1959 #define LANG_HOOKS_GET_ALIAS_SET d_get_alias_set
1960 #define LANG_HOOKS_TYPES_COMPATIBLE_P d_types_compatible_p
1961 #define LANG_HOOKS_BUILTIN_FUNCTION d_builtin_function
1962 #define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE d_builtin_function_ext_scope
1963 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE d_register_builtin_type
1964 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL d_finish_incomplete_decl
1965 #define LANG_HOOKS_GIMPLIFY_EXPR d_gimplify_expr
1966 #define LANG_HOOKS_CLASSIFY_RECORD d_classify_record
1967 #define LANG_HOOKS_TREE_SIZE d_tree_size
1968 #define LANG_HOOKS_PRINT_XNODE d_print_xnode
1969 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL d_dup_lang_specific_decl
1970 #define LANG_HOOKS_EH_PERSONALITY d_eh_personality
1971 #define LANG_HOOKS_EH_RUNTIME_TYPE d_build_eh_runtime_type
1972 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE d_enum_underlying_base_type
1973 #define LANG_HOOKS_PUSHDECL d_pushdecl
1974 #define LANG_HOOKS_GETDECLS d_getdecls
1975 #define LANG_HOOKS_GLOBAL_BINDINGS_P d_global_bindings_p
1976 #define LANG_HOOKS_TYPE_FOR_MODE d_type_for_mode
1977 #define LANG_HOOKS_TYPE_FOR_SIZE d_type_for_size
1978 #define LANG_HOOKS_TYPE_PROMOTES_TO d_type_promotes_to
1979 #define LANG_HOOKS_GET_SARIF_SOURCE_LANGUAGE d_get_sarif_source_language
1981 struct lang_hooks lang_hooks
= LANG_HOOKS_INITIALIZER
;
1983 #include "gt-d-d-lang.h"
1984 #include "gtype-d.h"