Define STAGE1_LIBS to link against libcl.a in stage1 on hpux.
[official-gcc.git] / gcc / d / d-lang.cc
blob4386a489ff2d2512c4d3673b8ae4cfb380d12427
1 /* d-lang.cc -- Language-dependent hooks for D.
2 Copyright (C) 2006-2021 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)
7 any later version.
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/>. */
18 #include "config.h"
19 #include "system.h"
20 #include "coretypes.h"
22 #include "dmd/aggregate.h"
23 #include "dmd/cond.h"
24 #include "dmd/declaration.h"
25 #include "dmd/doc.h"
26 #include "dmd/errors.h"
27 #include "dmd/expression.h"
28 #include "dmd/hdrgen.h"
29 #include "dmd/identifier.h"
30 #include "dmd/json.h"
31 #include "dmd/mangle.h"
32 #include "dmd/mars.h"
33 #include "dmd/module.h"
34 #include "dmd/mtype.h"
35 #include "dmd/target.h"
37 #include "opts.h"
38 #include "alias.h"
39 #include "tree.h"
40 #include "diagnostic.h"
41 #include "fold-const.h"
42 #include "toplev.h"
43 #include "langhooks.h"
44 #include "langhooks-def.h"
45 #include "target.h"
46 #include "function.h"
47 #include "stringpool.h"
48 #include "stor-layout.h"
49 #include "varasm.h"
50 #include "output.h"
51 #include "print-tree.h"
52 #include "debug.h"
54 #include "d-tree.h"
55 #include "id.h"
58 /* Array of D frontend type/decl nodes. */
59 tree d_global_trees[DTI_MAX];
61 /* True if compilation is currently inside the D frontend semantic passes. */
62 bool doing_semantic_analysis_p = false;
64 /* Options handled by the compiler that are separate from the frontend. */
65 struct d_option_data
67 const char *fonly; /* -fonly=<arg> */
68 const char *multilib; /* -imultilib <dir> */
69 const char *prefix; /* -iprefix <dir> */
71 bool deps; /* -M */
72 bool deps_skip_system; /* -MM */
73 const char *deps_filename; /* -M[M]D */
74 const char *deps_filename_user; /* -MF <arg> */
75 vec <const char *> deps_target; /* -M[QT] <arg> */
76 bool deps_phony; /* -MP */
78 bool stdinc; /* -nostdinc */
80 d_option;
82 /* List of modules being compiled. */
83 static Modules builtin_modules;
85 /* Module where `C main' is defined, compiled in if needed. */
86 static Module *entrypoint_module = NULL;
87 static Module *entrypoint_root_module = NULL;
89 /* The current and global binding level in effect. */
90 struct binding_level *current_binding_level;
91 struct binding_level *global_binding_level;
93 /* The context to be used for global declarations. */
94 static GTY(()) tree global_context;
96 /* Array of all global declarations to pass back to the middle-end. */
97 static GTY(()) vec <tree, va_gc> *global_declarations;
99 /* Support for GCC-style command-line make dependency generation.
100 Adds TARGET to the make dependencies target buffer.
101 QUOTED is true if the string should be quoted. */
103 static void
104 deps_add_target (const char *target, bool quoted)
106 obstack buffer;
107 gcc_obstack_init (&buffer);
109 if (!quoted)
111 obstack_grow0 (&buffer, target, strlen (target));
112 d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
113 return;
116 /* Quote characters in target which are significant to Make. */
117 unsigned slashes = 0;
119 for (const char *p = target; *p != '\0'; p++)
121 switch (*p)
123 case '\\':
124 slashes++;
125 break;
127 case ' ':
128 case '\t':
129 while (slashes--)
130 obstack_1grow (&buffer, '\\');
131 obstack_1grow (&buffer, '\\');
132 goto Ldef;
134 case '$':
135 obstack_1grow (&buffer, '$');
136 goto Ldef;
138 case '#':
139 case ':':
140 obstack_1grow (&buffer, '\\');
141 goto Ldef;
143 default:
144 Ldef:
145 slashes = 0;
146 break;
149 obstack_1grow (&buffer, *p);
152 obstack_1grow (&buffer, '\0');
153 d_option.deps_target.safe_push ((const char *) obstack_finish (&buffer));
156 /* Write STR, with a leading space to BUFFER, updating COLUMN as appropriate.
157 COLMAX is the number of columns to word-wrap at (0 means don't wrap). */
159 static void
160 deps_write_string (const char *str, obstack *buffer, unsigned &column,
161 unsigned colmax = 72)
163 unsigned size = strlen (str);
165 if (column != 0)
167 if (colmax && column + size > colmax)
169 obstack_grow (buffer, " \\\n ", 4);
170 column = 1;
172 else
174 obstack_1grow (buffer, ' ');
175 column++;
179 column += size;
180 obstack_grow (buffer, str, size);
183 /* Write out all dependencies of a given MODULE to the specified BUFFER. */
185 static void
186 deps_write (Module *module, obstack *buffer)
188 hash_set <const char *> seen_modules;
189 vec <const char *> dependencies = vNULL;
191 Modules modlist;
192 modlist.push (module);
194 vec <const char *> phonylist = vNULL;
195 unsigned column = 0;
197 /* Write out make target module name. */
198 if (d_option.deps_target.length ())
200 for (unsigned i = 0; i < d_option.deps_target.length (); i++)
201 deps_write_string (d_option.deps_target[i], buffer, column);
203 else
204 deps_write_string (module->objfile->name->str, buffer, column);
206 obstack_1grow (buffer, ':');
207 column++;
209 /* Search all modules for file dependencies. */
210 while (modlist.length > 0)
212 Module *depmod = modlist.pop ();
214 const char *modstr = depmod->srcfile->name->str;
216 /* Skip modules that have already been looked at. */
217 if (seen_modules.add (modstr))
218 continue;
220 dependencies.safe_push (modstr);
222 /* Add to list of phony targets if is not being compile. */
223 if (d_option.deps_phony && !depmod->isRoot ())
224 phonylist.safe_push (modstr);
226 /* Add imported files to dependency list. */
227 for (size_t i = 0; i < depmod->contentImportedFiles.length; i++)
229 const char *impstr = depmod->contentImportedFiles[i];
230 dependencies.safe_push (impstr);
231 phonylist.safe_push (impstr);
234 /* Search all imports of the module. */
235 for (size_t i = 0; i < depmod->aimports.length; i++)
237 Module *m = depmod->aimports[i];
239 /* Ignore compiler-generated modules. */
240 if ((m->ident == Identifier::idPool ("__entrypoint")
241 || m->ident == Identifier::idPool ("__main"))
242 && m->parent == NULL)
243 continue;
245 /* Don't search system installed modules, this includes
246 object, core.*, std.*, and gcc.* packages. */
247 if (d_option.deps_skip_system)
249 if (m->ident == Identifier::idPool ("object")
250 && m->parent == NULL)
251 continue;
253 if (m->md && m->md->packages)
255 Identifier *package = (*m->md->packages)[0];
257 if (package == Identifier::idPool ("core")
258 || package == Identifier::idPool ("std")
259 || package == Identifier::idPool ("gcc"))
260 continue;
264 modlist.push (m);
268 /* Write out all make dependencies. */
269 for (size_t i = 0; i < dependencies.length (); i++)
270 deps_write_string (dependencies[i], buffer, column);
272 obstack_1grow (buffer, '\n');
274 /* Write out all phony targets. */
275 for (size_t i = 0; i < phonylist.length (); i++)
277 const char *str = phonylist[i];
278 obstack_1grow (buffer, '\n');
279 obstack_grow (buffer, str, strlen (str));
280 obstack_grow (buffer, ":\n", 2);
283 obstack_1grow (buffer, '\0');
286 /* Implements the lang_hooks.init_options routine for language D.
287 This initializes the global state for the D frontend before calling
288 the option handlers. */
290 static void
291 d_init_options (unsigned int, cl_decoded_option *decoded_options)
293 /* Set default values. */
294 global._init ();
296 global.vendor = lang_hooks.name;
297 global.params.argv0 = xstrdup (decoded_options[0].arg);
298 global.params.link = true;
299 global.params.useAssert = CHECKENABLEdefault;
300 global.params.useInvariants = CHECKENABLEdefault;
301 global.params.useIn = CHECKENABLEdefault;
302 global.params.useOut = CHECKENABLEdefault;
303 global.params.useArrayBounds = CHECKENABLEdefault;
304 global.params.useSwitchError = CHECKENABLEdefault;
305 global.params.checkAction = CHECKACTION_D;
306 global.params.useModuleInfo = true;
307 global.params.useTypeInfo = true;
308 global.params.useExceptions = true;
309 global.params.useInline = false;
310 global.params.obj = true;
311 global.params.hdrStripPlainFunctions = true;
312 global.params.betterC = false;
313 global.params.allInst = false;
314 global.params.errorLimit = flag_max_errors;
316 /* Default extern(C++) mangling to C++14. */
317 global.params.cplusplus = CppStdRevisionCpp14;
319 /* Warnings and deprecations are disabled by default. */
320 global.params.useDeprecated = DIAGNOSTICinform;
321 global.params.warnings = DIAGNOSTICoff;
323 global.params.imppath = new Strings ();
324 global.params.fileImppath = new Strings ();
326 /* Extra GDC-specific options. */
327 d_option.fonly = NULL;
328 d_option.multilib = NULL;
329 d_option.prefix = NULL;
330 d_option.deps = false;
331 d_option.deps_skip_system = false;
332 d_option.deps_filename = NULL;
333 d_option.deps_filename_user = NULL;
334 d_option.deps_target = vNULL;
335 d_option.deps_phony = false;
336 d_option.stdinc = true;
339 /* Implements the lang_hooks.init_options_struct routine for language D.
340 Initializes the options structure OPTS. */
342 static void
343 d_init_options_struct (gcc_options *opts)
345 /* GCC options. */
346 opts->x_flag_exceptions = 1;
348 /* Unlike C, there is no global `errno' variable. */
349 opts->x_flag_errno_math = 0;
350 opts->frontend_set_flag_errno_math = true;
352 /* D says that signed overflow is precisely defined. */
353 opts->x_flag_wrapv = 1;
356 /* Implements the lang_hooks.lang_mask routine for language D.
357 Returns language mask for option parsing. */
359 static unsigned int
360 d_option_lang_mask (void)
362 return CL_D;
365 /* Implements the lang_hooks.init routine for language D. */
367 static bool
368 d_init (void)
370 Type::_init ();
371 Id::initialize ();
372 Module::_init ();
373 Expression::_init ();
374 Objc::_init ();
376 /* Back-end init. */
377 global_binding_level = ggc_cleared_alloc <binding_level> ();
378 current_binding_level = global_binding_level;
380 /* This allows the code in d-builtins.cc to not have to worry about
381 converting (C signed char *) to (D char *) for string arguments of
382 built-in functions. The parameter (signed_char = false) specifies
383 whether char is signed. */
384 build_common_tree_nodes (false);
386 d_init_builtins ();
388 if (flag_exceptions)
389 using_eh_for_cleanups ();
391 if (!supports_one_only ())
392 flag_weak_templates = 0;
394 /* This is the C main, not the D main. */
395 main_identifier_node = get_identifier ("main");
397 target._init (global.params);
398 d_init_versions ();
400 /* Insert all library-configured identifiers and import paths. */
401 add_import_paths (d_option.prefix, d_option.multilib, d_option.stdinc);
403 return 1;
406 /* Implements the lang_hooks.init_ts routine for language D. */
408 static void
409 d_init_ts (void)
411 MARK_TS_TYPED (FLOAT_MOD_EXPR);
412 MARK_TS_TYPED (UNSIGNED_RSHIFT_EXPR);
415 /* Implements the lang_hooks.handle_option routine for language D.
416 Handles D specific options. Return false if we didn't do anything. */
418 static bool
419 d_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
420 int kind ATTRIBUTE_UNUSED,
421 location_t loc ATTRIBUTE_UNUSED,
422 const cl_option_handlers *handlers ATTRIBUTE_UNUSED)
424 opt_code code = (opt_code) scode;
425 bool result = true;
427 switch (code)
429 case OPT_fall_instantiations:
430 global.params.allInst = value;
431 break;
433 case OPT_fassert:
434 global.params.useAssert = value ? CHECKENABLEon : CHECKENABLEoff;
435 break;
437 case OPT_fbounds_check:
438 global.params.useArrayBounds = value ? CHECKENABLEon : CHECKENABLEoff;
439 break;
441 case OPT_fbounds_check_:
442 global.params.useArrayBounds = (value == 2) ? CHECKENABLEon
443 : (value == 1) ? CHECKENABLEsafeonly : CHECKENABLEoff;
444 break;
446 case OPT_fdebug:
447 global.params.debuglevel = value ? 1 : 0;
448 break;
450 case OPT_fdebug_:
451 if (ISDIGIT (arg[0]))
453 int level = integral_argument (arg);
454 if (level != -1)
456 global.params.debuglevel = level;
457 break;
461 if (Identifier::isValidIdentifier (CONST_CAST (char *, arg)))
463 if (!global.params.debugids)
464 global.params.debugids = new Strings ();
465 global.params.debugids->push (arg);
466 break;
469 error ("bad argument for %<-fdebug%>: %qs", arg);
470 break;
472 case OPT_fdoc:
473 global.params.doDocComments = value;
474 break;
476 case OPT_fdoc_dir_:
477 global.params.doDocComments = true;
478 global.params.docdir = arg;
479 break;
481 case OPT_fdoc_file_:
482 global.params.doDocComments = true;
483 global.params.docname = arg;
484 break;
486 case OPT_fdoc_inc_:
487 global.params.ddocfiles.push (arg);
488 break;
490 case OPT_fdruntime:
491 global.params.betterC = !value;
492 break;
494 case OPT_fdump_d_original:
495 global.params.vcg_ast = value;
496 break;
498 case OPT_fexceptions:
499 global.params.useExceptions = value;
500 break;
502 case OPT_fignore_unknown_pragmas:
503 global.params.ignoreUnsupportedPragmas = value;
504 break;
506 case OPT_finvariants:
507 global.params.useInvariants = value ? CHECKENABLEon : CHECKENABLEoff;
508 break;
510 case OPT_fmain:
511 global.params.addMain = value;
512 break;
514 case OPT_fmodule_file_:
515 global.params.modFileAliasStrings.push (arg);
516 if (!strchr (arg, '='))
517 error ("bad argument for %<-fmodule-file%>: %qs", arg);
518 break;
520 case OPT_fmoduleinfo:
521 global.params.useModuleInfo = value;
522 break;
524 case OPT_fonly_:
525 d_option.fonly = arg;
526 break;
528 case OPT_fpostconditions:
529 global.params.useOut = value ? CHECKENABLEon : CHECKENABLEoff;
530 break;
532 case OPT_fpreconditions:
533 global.params.useIn = value ? CHECKENABLEon : CHECKENABLEoff;
534 break;
536 case OPT_frelease:
537 global.params.release = value;
538 break;
540 case OPT_frtti:
541 global.params.useTypeInfo = value;
542 break;
544 case OPT_fswitch_errors:
545 global.params.useSwitchError = value ? CHECKENABLEon : CHECKENABLEoff;
546 break;
548 case OPT_ftransition_all:
549 global.params.vtls = value;
550 global.params.vfield = value;
551 global.params.vcomplex = value;
552 break;
554 case OPT_ftransition_complex:
555 global.params.vcomplex = value;
556 break;
558 case OPT_ftransition_dip1000:
559 global.params.vsafe = value;
560 global.params.useDIP25 = value;
561 break;
563 case OPT_ftransition_dip25:
564 global.params.useDIP25 = value;
565 break;
567 case OPT_ftransition_field:
568 global.params.vfield = value;
569 break;
571 case OPT_ftransition_nogc:
572 global.params.vgc = value;
573 break;
575 case OPT_ftransition_tls:
576 global.params.vtls = value;
577 break;
579 case OPT_funittest:
580 global.params.useUnitTests = value;
581 break;
583 case OPT_fversion_:
584 if (ISDIGIT (arg[0]))
586 int level = integral_argument (arg);
587 if (level != -1)
589 global.params.versionlevel = level;
590 break;
594 if (Identifier::isValidIdentifier (CONST_CAST (char *, arg)))
596 if (!global.params.versionids)
597 global.params.versionids = new Strings ();
598 global.params.versionids->push (arg);
599 break;
602 error ("bad argument for %<-fversion%>: %qs", arg);
603 break;
605 case OPT_H:
606 global.params.doHdrGeneration = true;
607 break;
609 case OPT_Hd:
610 global.params.doHdrGeneration = true;
611 global.params.hdrdir = arg;
612 break;
614 case OPT_Hf:
615 global.params.doHdrGeneration = true;
616 global.params.hdrname = arg;
617 break;
619 case OPT_imultilib:
620 d_option.multilib = arg;
621 break;
623 case OPT_iprefix:
624 d_option.prefix = arg;
625 break;
627 case OPT_I:
628 global.params.imppath->push (arg);
629 break;
631 case OPT_J:
632 global.params.fileImppath->push (arg);
633 break;
635 case OPT_MM:
636 d_option.deps_skip_system = true;
637 /* Fall through. */
639 case OPT_M:
640 d_option.deps = true;
641 break;
643 case OPT_MMD:
644 d_option.deps_skip_system = true;
645 /* Fall through. */
647 case OPT_MD:
648 d_option.deps = true;
649 d_option.deps_filename = arg;
650 break;
652 case OPT_MF:
653 /* If specified multiple times, last one wins. */
654 d_option.deps_filename_user = arg;
655 break;
657 case OPT_MP:
658 d_option.deps_phony = true;
659 break;
661 case OPT_MQ:
662 deps_add_target (arg, true);
663 break;
665 case OPT_MT:
666 deps_add_target (arg, false);
667 break;
669 case OPT_nostdinc:
670 d_option.stdinc = false;
671 break;
673 case OPT_v:
674 global.params.verbose = value;
675 break;
677 case OPT_Wall:
678 if (value)
679 global.params.warnings = DIAGNOSTICinform;
680 break;
682 case OPT_Wdeprecated:
683 global.params.useDeprecated = value ? DIAGNOSTICinform : DIAGNOSTICoff;
684 break;
686 case OPT_Werror:
687 if (value)
688 global.params.warnings = DIAGNOSTICerror;
689 break;
691 case OPT_Wspeculative:
692 if (value)
693 global.params.showGaggedErrors = 1;
694 break;
696 case OPT_Xf:
697 global.params.jsonfilename = arg;
698 /* Fall through. */
700 case OPT_X:
701 global.params.doJsonGeneration = true;
702 break;
704 default:
705 break;
708 D_handle_option_auto (&global_options, &global_options_set,
709 scode, arg, value,
710 d_option_lang_mask (), kind,
711 loc, handlers, global_dc);
713 return result;
716 /* Implements the lang_hooks.post_options routine for language D.
717 Deal with any options that imply the turning on/off of features.
718 FN is the main input filename passed on the command line. */
720 static bool
721 d_post_options (const char ** fn)
723 /* Verify the input file name. */
724 const char *filename = *fn;
725 if (!filename || strcmp (filename, "-") == 0)
726 filename = "";
728 /* The front end considers the first input file to be the main one. */
729 *fn = filename;
731 /* Release mode doesn't turn off bounds checking for safe functions. */
732 if (global.params.useArrayBounds == CHECKENABLEdefault)
734 global.params.useArrayBounds = global.params.release
735 ? CHECKENABLEsafeonly : CHECKENABLEon;
738 /* Assert code is generated if unittests are being compiled also, even if
739 release mode is turned on. */
740 if (global.params.useAssert == CHECKENABLEdefault)
742 if (global.params.useUnitTests || !global.params.release)
743 global.params.useAssert = CHECKENABLEon;
744 else
745 global.params.useAssert = CHECKENABLEoff;
748 /* Checks for switches without a default are turned off in release mode. */
749 if (global.params.useSwitchError == CHECKENABLEdefault)
751 global.params.useSwitchError = global.params.release
752 ? CHECKENABLEoff : CHECKENABLEon;
755 /* Contracts are turned off in release mode. */
756 if (global.params.useInvariants == CHECKENABLEdefault)
758 global.params.useInvariants = global.params.release
759 ? CHECKENABLEoff : CHECKENABLEon;
762 if (global.params.useIn == CHECKENABLEdefault)
764 global.params.useIn = global.params.release
765 ? CHECKENABLEoff : CHECKENABLEon;
768 if (global.params.useOut == CHECKENABLEdefault)
770 global.params.useOut = global.params.release
771 ? CHECKENABLEoff : CHECKENABLEon;
774 if (global.params.betterC)
776 if (!global_options_set.x_flag_moduleinfo)
777 global.params.useModuleInfo = false;
779 if (!global_options_set.x_flag_rtti)
780 global.params.useTypeInfo = false;
782 if (!global_options_set.x_flag_exceptions)
783 global.params.useExceptions = false;
785 global.params.checkAction = CHECKACTION_C;
788 /* Keep in sync with existing -fbounds-check flag. */
789 flag_bounds_check = (global.params.useArrayBounds == CHECKENABLEon);
791 /* Turn off partitioning unless it was explicitly requested, as it doesn't
792 work with D exception chaining, where EH handler uses LSDA to determine
793 whether two thrown exception are in the same context. */
794 if (!global_options_set.x_flag_reorder_blocks_and_partition)
795 global_options.x_flag_reorder_blocks_and_partition = 0;
797 /* Error about use of deprecated features. */
798 if (global.params.useDeprecated == DIAGNOSTICinform
799 && global.params.warnings == DIAGNOSTICerror)
800 global.params.useDeprecated = DIAGNOSTICerror;
802 /* Make -fmax-errors visible to frontend's diagnostic machinery. */
803 if (global_options_set.x_flag_max_errors)
804 global.params.errorLimit = flag_max_errors;
806 if (flag_excess_precision == EXCESS_PRECISION_DEFAULT)
807 flag_excess_precision = EXCESS_PRECISION_STANDARD;
809 global.params.symdebug = write_symbols != NO_DEBUG;
810 global.params.useInline = flag_inline_functions;
811 global.params.showColumns = flag_show_column;
813 if (global.params.useInline)
814 global.params.hdrStripPlainFunctions = false;
816 global.params.obj = !flag_syntax_only;
818 /* Has no effect yet. */
819 global.params.pic = flag_pic != 0;
821 /* Add in versions given on the command line. */
822 if (global.params.versionids)
824 for (size_t i = 0; i < global.params.versionids->length; i++)
826 const char *s = (*global.params.versionids)[i];
827 VersionCondition::addGlobalIdent (s);
831 if (global.params.debugids)
833 for (size_t i = 0; i < global.params.debugids->length; i++)
835 const char *s = (*global.params.debugids)[i];
836 DebugCondition::addGlobalIdent (s);
840 if (warn_return_type == -1)
841 warn_return_type = 0;
843 return false;
846 /* Add the module M to the list of modules that may declare GCC builtins.
847 These are scanned after first semantic and before codegen passes.
848 See d_maybe_set_builtin() for the implementation. */
850 void
851 d_add_builtin_module (Module *m)
853 builtin_modules.push (m);
856 /* Record the entrypoint module ENTRY which will be compiled in the current
857 compilation. ROOT is the module scope where this was requested from. */
859 void
860 d_add_entrypoint_module (Module *entry, Module *root)
862 /* We are emitting this straight to object file. */
863 entrypoint_module = entry;
864 entrypoint_root_module = root;
867 /* Implements the lang_hooks.parse_file routine for language D. */
869 static void
870 d_parse_file (void)
872 if (global.params.verbose)
874 message ("binary %s", global.params.argv0.ptr);
875 message ("version %s", global.version.ptr);
877 if (global.versionids)
879 obstack buffer;
880 gcc_obstack_init (&buffer);
881 obstack_grow (&buffer, "predefs ", 9);
882 for (size_t i = 0; i < global.versionids->length; i++)
884 Identifier *id = (*global.versionids)[i];
885 const char *str = id->toChars ();
886 obstack_1grow (&buffer, ' ');
887 obstack_grow (&buffer, str, strlen (str));
890 obstack_1grow (&buffer, '\0');
891 message ("%s", (char *) obstack_finish (&buffer));
895 /* Start the main input file, if the debug writer wants it. */
896 if (debug_hooks->start_end_main_source_file)
897 debug_hooks->start_source_file (0, main_input_filename);
899 /* Create Module's for all sources we will load. */
900 Modules modules;
901 modules.reserve (num_in_fnames);
903 /* In this mode, the first file name is supposed to be a duplicate
904 of one of the input files. */
905 if (d_option.fonly && strcmp (d_option.fonly, main_input_filename) != 0)
906 error ("%<-fonly=%> argument is different from first input file name");
908 for (size_t i = 0; i < num_in_fnames; i++)
910 if (strcmp (in_fnames[i], "-") == 0)
912 /* Load the entire contents of stdin into memory. 8 kilobytes should
913 be a good enough initial size, but double on each iteration.
914 16 bytes are added for the final '\n' and 15 bytes of padding. */
915 ssize_t size = 8 * 1024;
916 uchar *buffer = XNEWVEC (uchar, size + 16);
917 ssize_t len = 0;
918 ssize_t count;
920 while ((count = read (STDIN_FILENO, buffer + len, size - len)) > 0)
922 len += count;
923 if (len == size)
925 size *= 2;
926 buffer = XRESIZEVEC (uchar, buffer, size + 16);
930 if (count < 0)
932 error (Loc ("stdin", 0, 0), "%s", xstrerror (errno));
933 free (buffer);
934 continue;
937 /* Handling stdin, generate a unique name for the module. */
938 Module *m = Module::create (in_fnames[i],
939 Identifier::generateId ("__stdin"),
940 global.params.doDocComments,
941 global.params.doHdrGeneration);
942 modules.push (m);
944 /* Overwrite the source file for the module, the one created by
945 Module::create would have a forced a `.d' suffix. */
946 m->srcfile = File::create ("<stdin>");
947 m->srcfile->len = len;
948 m->srcfile->buffer = buffer;
950 else
952 /* Handling a D source file, strip off the path and extension. */
953 const char *basename = FileName::name (in_fnames[i]);
954 const char *name = FileName::removeExt (basename);
956 Module *m = Module::create (in_fnames[i], Identifier::idPool (name),
957 global.params.doDocComments,
958 global.params.doHdrGeneration);
959 modules.push (m);
960 FileName::free (name);
964 /* Read all D source files. */
965 for (size_t i = 0; i < modules.length; i++)
967 Module *m = modules[i];
968 m->read (Loc ());
971 /* Parse all D source files. */
972 for (size_t i = 0; i < modules.length; i++)
974 Module *m = modules[i];
976 if (global.params.verbose)
977 message ("parse %s", m->toChars ());
979 if (!Module::rootModule)
980 Module::rootModule = m;
982 m->importedFrom = m;
983 m->parse ();
985 if (m->isDocFile)
987 gendocfile (m);
988 /* Remove M from list of modules. */
989 modules.remove (i);
990 i--;
994 /* Load the module containing D main. */
995 if (global.params.addMain)
997 unsigned errors = global.startGagging ();
998 Module *m = Module::load (Loc (), NULL, Identifier::idPool ("__main"));
1000 if (!global.endGagging (errors))
1002 m->importedFrom = m;
1003 modules.push (m);
1007 /* If an error occurs later during compilation, remember that we generated
1008 the headers, so that they can be removed before exit. */
1009 bool dump_headers = false;
1011 if (global.errors)
1012 goto had_errors;
1014 if (global.params.doHdrGeneration)
1016 /* Generate 'header' import files. Since 'header' import files must be
1017 independent of command line switches and what else is imported, they
1018 are generated before any semantic analysis. */
1019 for (size_t i = 0; i < modules.length; i++)
1021 Module *m = modules[i];
1022 if (d_option.fonly && m != Module::rootModule)
1023 continue;
1025 if (global.params.verbose)
1026 message ("import %s", m->toChars ());
1028 genhdrfile (m);
1031 dump_headers = true;
1034 if (global.errors)
1035 goto had_errors;
1037 /* Load all unconditional imports for better symbol resolving. */
1038 for (size_t i = 0; i < modules.length; i++)
1040 Module *m = modules[i];
1042 if (global.params.verbose)
1043 message ("importall %s", m->toChars ());
1045 m->importAll (NULL);
1048 if (global.errors)
1049 goto had_errors;
1051 /* Do semantic analysis. */
1052 doing_semantic_analysis_p = true;
1054 for (size_t i = 0; i < modules.length; i++)
1056 Module *m = modules[i];
1058 if (global.params.verbose)
1059 message ("semantic %s", m->toChars ());
1061 dsymbolSemantic (m, NULL);
1064 /* Do deferred semantic analysis. */
1065 Module::dprogress = 1;
1066 Module::runDeferredSemantic ();
1068 if (Module::deferred.length)
1070 for (size_t i = 0; i < Module::deferred.length; i++)
1072 Dsymbol *sd = Module::deferred[i];
1073 error_at (make_location_t (sd->loc),
1074 "unable to resolve forward reference in definition");
1078 /* Process all built-in modules or functions now for CTFE. */
1079 while (builtin_modules.length != 0)
1081 Module *m = builtin_modules.pop ();
1082 d_maybe_set_builtin (m);
1085 /* Do pass 2 semantic analysis. */
1086 for (size_t i = 0; i < modules.length; i++)
1088 Module *m = modules[i];
1090 if (global.params.verbose)
1091 message ("semantic2 %s", m->toChars ());
1093 semantic2 (m, NULL);
1096 Module::runDeferredSemantic2 ();
1098 if (global.errors)
1099 goto had_errors;
1101 /* Do pass 3 semantic analysis. */
1102 for (size_t i = 0; i < modules.length; i++)
1104 Module *m = modules[i];
1106 if (global.params.verbose)
1107 message ("semantic3 %s", m->toChars ());
1109 semantic3 (m, NULL);
1112 Module::runDeferredSemantic3 ();
1114 /* Check again, incase semantic3 pass loaded any more modules. */
1115 while (builtin_modules.length != 0)
1117 Module *m = builtin_modules.pop ();
1118 d_maybe_set_builtin (m);
1121 /* Do not attempt to generate output files if errors or warnings occurred. */
1122 if (global.errors || global.warnings)
1123 goto had_errors;
1125 /* Generate output files. */
1126 doing_semantic_analysis_p = false;
1128 if (Module::rootModule)
1130 /* Declare the name of the root module as the first global name in order
1131 to make the middle-end fully deterministic. */
1132 OutBuffer buf;
1133 mangleToBuffer (Module::rootModule, &buf);
1134 first_global_object_name = buf.extractChars ();
1137 /* Make dependencies. */
1138 if (d_option.deps)
1140 obstack buffer;
1141 FILE *deps_stream;
1143 gcc_obstack_init (&buffer);
1145 for (size_t i = 0; i < modules.length; i++)
1146 deps_write (modules[i], &buffer);
1148 /* -MF <arg> overrides -M[M]D. */
1149 if (d_option.deps_filename_user)
1150 d_option.deps_filename = d_option.deps_filename_user;
1152 if (d_option.deps_filename)
1154 deps_stream = fopen (d_option.deps_filename, "w");
1155 if (!deps_stream)
1157 fatal_error (input_location, "opening dependency file %s: %m",
1158 d_option.deps_filename);
1159 goto had_errors;
1162 else
1163 deps_stream = stdout;
1165 fprintf (deps_stream, "%s", (char *) obstack_finish (&buffer));
1167 if (deps_stream != stdout
1168 && (ferror (deps_stream) || fclose (deps_stream)))
1170 fatal_error (input_location, "closing dependency file %s: %m",
1171 d_option.deps_filename);
1175 /* Generate JSON files. */
1176 if (global.params.doJsonGeneration)
1178 OutBuffer buf;
1179 json_generate (&buf, &modules);
1181 const char *name = global.params.jsonfilename.ptr;
1182 FILE *json_stream;
1184 if (name && (name[0] != '-' || name[1] != '\0'))
1186 const char *nameext
1187 = FileName::defaultExt (name, global.json_ext.ptr);
1188 json_stream = fopen (nameext, "w");
1189 if (!json_stream)
1191 fatal_error (input_location, "opening json file %s: %m", nameext);
1192 goto had_errors;
1195 else
1196 json_stream = stdout;
1198 fprintf (json_stream, "%s", buf.peekChars ());
1200 if (json_stream != stdout
1201 && (ferror (json_stream) || fclose (json_stream)))
1202 fatal_error (input_location, "closing json file %s: %m", name);
1205 /* Generate Ddoc files. */
1206 if (global.params.doDocComments && !global.errors && !errorcount)
1208 for (size_t i = 0; i < modules.length; i++)
1210 Module *m = modules[i];
1211 gendocfile (m);
1215 /* Handle -fdump-d-original. */
1216 if (global.params.vcg_ast)
1218 for (size_t i = 0; i < modules.length; i++)
1220 Module *m = modules[i];
1221 OutBuffer buf;
1222 buf.doindent = 1;
1224 moduleToBuffer (&buf, m);
1225 message ("%s", buf.peekChars ());
1229 for (size_t i = 0; i < modules.length; i++)
1231 Module *m = modules[i];
1232 if (d_option.fonly && m != Module::rootModule)
1233 continue;
1235 if (global.params.verbose)
1236 message ("code %s", m->toChars ());
1238 if (!flag_syntax_only)
1240 if ((entrypoint_module != NULL) && (m == entrypoint_root_module))
1241 build_decl_tree (entrypoint_module);
1243 build_decl_tree (m);
1247 /* And end the main input file, if the debug writer wants it. */
1248 if (debug_hooks->start_end_main_source_file)
1249 debug_hooks->end_source_file (0);
1251 had_errors:
1252 /* Add the D frontend error count to the GCC error count to correctly
1253 exit with an error status. */
1254 errorcount += (global.errors + global.warnings);
1256 /* Remove generated .di files on error. */
1257 if (errorcount && dump_headers)
1259 for (size_t i = 0; i < modules.length; i++)
1261 Module *m = modules[i];
1262 if (d_option.fonly && m != Module::rootModule)
1263 continue;
1265 remove (m->hdrfile->toChars ());
1269 /* Write out globals. */
1270 d_finish_compilation (vec_safe_address (global_declarations),
1271 vec_safe_length (global_declarations));
1274 /* Implements the lang_hooks.types.type_for_mode routine for language D. */
1276 static tree
1277 d_type_for_mode (machine_mode mode, int unsignedp)
1279 if (mode == QImode)
1280 return unsignedp ? d_ubyte_type : d_byte_type;
1282 if (mode == HImode)
1283 return unsignedp ? d_ushort_type : d_short_type;
1285 if (mode == SImode)
1286 return unsignedp ? d_uint_type : d_int_type;
1288 if (mode == DImode)
1289 return unsignedp ? d_ulong_type : d_long_type;
1291 if (mode == TYPE_MODE (d_cent_type))
1292 return unsignedp ? d_ucent_type : d_cent_type;
1294 if (mode == TYPE_MODE (float_type_node))
1295 return float_type_node;
1297 if (mode == TYPE_MODE (double_type_node))
1298 return double_type_node;
1300 if (mode == TYPE_MODE (long_double_type_node))
1301 return long_double_type_node;
1303 if (mode == TYPE_MODE (build_pointer_type (char8_type_node)))
1304 return build_pointer_type (char8_type_node);
1306 if (mode == TYPE_MODE (build_pointer_type (d_int_type)))
1307 return build_pointer_type (d_int_type);
1309 for (int i = 0; i < NUM_INT_N_ENTS; i ++)
1311 if (int_n_enabled_p[i] && mode == int_n_data[i].m)
1313 if (unsignedp)
1314 return int_n_trees[i].unsigned_type;
1315 else
1316 return int_n_trees[i].signed_type;
1320 if (COMPLEX_MODE_P (mode))
1322 machine_mode inner_mode;
1323 tree inner_type;
1325 if (mode == TYPE_MODE (complex_float_type_node))
1326 return complex_float_type_node;
1327 if (mode == TYPE_MODE (complex_double_type_node))
1328 return complex_double_type_node;
1329 if (mode == TYPE_MODE (complex_long_double_type_node))
1330 return complex_long_double_type_node;
1332 inner_mode = (machine_mode) GET_MODE_INNER (mode);
1333 inner_type = d_type_for_mode (inner_mode, unsignedp);
1334 if (inner_type != NULL_TREE)
1335 return build_complex_type (inner_type);
1337 else if (VECTOR_MODE_P (mode))
1339 machine_mode inner_mode = (machine_mode) GET_MODE_INNER (mode);
1340 tree inner_type = d_type_for_mode (inner_mode, unsignedp);
1341 if (inner_type != NULL_TREE)
1342 return build_vector_type_for_mode (inner_type, mode);
1345 return 0;
1348 /* Implements the lang_hooks.types.type_for_size routine for language D. */
1350 static tree
1351 d_type_for_size (unsigned bits, int unsignedp)
1353 if (bits <= TYPE_PRECISION (d_byte_type))
1354 return unsignedp ? d_ubyte_type : d_byte_type;
1356 if (bits <= TYPE_PRECISION (d_short_type))
1357 return unsignedp ? d_ushort_type : d_short_type;
1359 if (bits <= TYPE_PRECISION (d_int_type))
1360 return unsignedp ? d_uint_type : d_int_type;
1362 if (bits <= TYPE_PRECISION (d_long_type))
1363 return unsignedp ? d_ulong_type : d_long_type;
1365 if (bits <= TYPE_PRECISION (d_cent_type))
1366 return unsignedp ? d_ucent_type : d_cent_type;
1368 for (int i = 0; i < NUM_INT_N_ENTS; i ++)
1370 if (int_n_enabled_p[i] && bits == int_n_data[i].bitsize)
1372 if (unsignedp)
1373 return int_n_trees[i].unsigned_type;
1374 else
1375 return int_n_trees[i].signed_type;
1379 return 0;
1382 /* Implements the lang_hooks.types.type_promotes_to routine for language D. */
1384 static tree
1385 d_type_promotes_to (tree type)
1387 /* Promotions are only applied on unnamed function arguments for declarations
1388 with `extern(C)' or `extern(C++)' linkage. */
1389 if (cfun && DECL_LANG_FRONTEND (cfun->decl)
1390 && DECL_LANG_FRONTEND (cfun->decl)->linkage != LINKd)
1392 /* In [type/integer-promotions], integer promotions are conversions of the
1393 following types:
1395 bool int
1396 byte int
1397 ubyte int
1398 short int
1399 ushort int
1400 char int
1401 wchar int
1402 dchar uint
1404 If an enum has as a base type one of the types in the left column, it
1405 is converted to the type in the right column. */
1406 if (TREE_CODE (type) == ENUMERAL_TYPE && ENUM_IS_SCOPED (type))
1407 type = TREE_TYPE (type);
1409 type = TYPE_MAIN_VARIANT (type);
1411 /* Check for promotions of target-defined types first. */
1412 tree promoted_type = targetm.promoted_type (type);
1413 if (promoted_type)
1414 return promoted_type;
1416 if (TREE_CODE (type) == BOOLEAN_TYPE)
1417 return d_int_type;
1419 if (INTEGRAL_TYPE_P (type))
1421 if (type == d_byte_type || type == d_ubyte_type
1422 || type == d_short_type || type == d_ushort_type
1423 || type == char8_type_node || type == char16_type_node)
1424 return d_int_type;
1426 if (type == char32_type_node)
1427 return d_uint_type;
1429 if (TYPE_PRECISION (type) < TYPE_PRECISION (d_int_type))
1430 return d_int_type;
1433 /* Float arguments are converted to doubles. */
1434 if (type == float_type_node)
1435 return double_type_node;
1437 if (type == ifloat_type_node)
1438 return idouble_type_node;
1441 return type;
1444 /* Implements the lang_hooks.decls.global_bindings_p routine for language D.
1445 Return true if we are in the global binding level. */
1447 static bool
1448 d_global_bindings_p (void)
1450 return (current_binding_level == global_binding_level);
1453 /* Return global_context, but create it first if need be. */
1455 static tree
1456 get_global_context (void)
1458 if (!global_context)
1460 global_context = build_translation_unit_decl (NULL_TREE);
1461 debug_hooks->register_main_translation_unit (global_context);
1464 return global_context;
1467 /* Implements the lang_hooks.decls.pushdecl routine for language D.
1468 Record DECL as belonging to the current lexical scope. */
1470 tree
1471 d_pushdecl (tree decl)
1473 /* Set the context of the decl. If current_function_decl did not help in
1474 determining the context, use global scope. */
1475 if (!DECL_CONTEXT (decl))
1477 if (current_function_decl)
1478 DECL_CONTEXT (decl) = current_function_decl;
1479 else
1480 DECL_CONTEXT (decl) = get_global_context ();
1483 /* Put decls on list in reverse order. */
1484 if (TREE_STATIC (decl) || d_global_bindings_p ())
1485 vec_safe_push (global_declarations, decl);
1486 else
1488 TREE_CHAIN (decl) = current_binding_level->names;
1489 current_binding_level->names = decl;
1492 return decl;
1495 /* Implements the lang_hooks.decls.getdecls routine for language D.
1496 Return the list of declarations of the current level. */
1498 static tree
1499 d_getdecls (void)
1501 if (current_binding_level)
1502 return current_binding_level->names;
1504 return NULL_TREE;
1508 /* Implements the lang_hooks.get_alias_set routine for language D.
1509 Get the alias set corresponding to type or expression T.
1510 Return -1 if we don't do anything special. */
1512 static alias_set_type
1513 d_get_alias_set (tree)
1515 /* For now in D, assume everything aliases everything else, until we define
1516 some solid rules backed by a specification. There are also some parts
1517 of code generation routines that don't adhere to C alias rules, such as
1518 build_vconvert. In any case, a lot of user code already assumes there
1519 is no strict aliasing and will break if we were to change that. */
1520 return 0;
1523 /* Implements the lang_hooks.types_compatible_p routine for language D.
1524 Compares two types for equivalence in the D programming language.
1525 This routine should only return 1 if it is sure, even though the frontend
1526 should have already ensured that all types are compatible before handing
1527 over the parsed ASTs to the code generator. */
1529 static int
1530 d_types_compatible_p (tree x, tree y)
1532 Type *tx = TYPE_LANG_FRONTEND (x);
1533 Type *ty = TYPE_LANG_FRONTEND (y);
1535 /* Try validating the types in the frontend. */
1536 if (tx != NULL && ty != NULL)
1538 /* Types are equivalent. */
1539 if (same_type_p (tx, ty))
1540 return true;
1542 /* Type system allows implicit conversion between. */
1543 if (tx->implicitConvTo (ty) || ty->implicitConvTo (tx))
1544 return true;
1547 /* Fallback on using type flags for comparison. E.g: all dynamic arrays
1548 are distinct types in D, but are VIEW_CONVERT compatible. */
1549 if (TREE_CODE (x) == RECORD_TYPE && TREE_CODE (y) == RECORD_TYPE)
1551 if (TYPE_DYNAMIC_ARRAY (x) && TYPE_DYNAMIC_ARRAY (y))
1552 return true;
1554 if (TYPE_DELEGATE (x) && TYPE_DELEGATE (y))
1555 return true;
1557 if (TYPE_ASSOCIATIVE_ARRAY (x) && TYPE_ASSOCIATIVE_ARRAY (y))
1558 return true;
1561 return false;
1564 /* Implements the lang_hooks.finish_incomplete_decl routine for language D. */
1566 static void
1567 d_finish_incomplete_decl (tree decl)
1569 if (VAR_P (decl))
1571 /* D allows zero-length declarations. Such a declaration ends up with
1572 DECL_SIZE (t) == NULL_TREE which is what the back-end function
1573 assembler_variable checks. This could change in later versions, or
1574 maybe all of these variables should be aliased to one symbol. */
1575 if (DECL_SIZE (decl) == 0)
1577 DECL_SIZE (decl) = bitsize_zero_node;
1578 DECL_SIZE_UNIT (decl) = size_zero_node;
1583 /* Implements the lang_hooks.types.classify_record routine for language D.
1584 Return the true debug type for TYPE. */
1586 static classify_record
1587 d_classify_record (tree type)
1589 Type *t = TYPE_LANG_FRONTEND (type);
1590 TypeClass *tc = t ? t->isTypeClass () : NULL;
1592 if (tc != NULL)
1594 /* extern(C++) interfaces get emitted as classes. */
1595 if (tc->sym->isInterfaceDeclaration ()
1596 && !tc->sym->isCPPinterface ())
1597 return RECORD_IS_INTERFACE;
1599 return RECORD_IS_CLASS;
1602 return RECORD_IS_STRUCT;
1605 /* Implements the lang_hooks.tree_size routine for language D.
1606 Determine the size of our tcc_constant or tcc_exceptional nodes. */
1608 static size_t
1609 d_tree_size (tree_code code)
1611 switch (code)
1613 case FUNCFRAME_INFO:
1614 return sizeof (tree_frame_info);
1616 default:
1617 gcc_unreachable ();
1621 /* Implements the lang_hooks.print_xnode routine for language D. */
1623 static void
1624 d_print_xnode (FILE *file, tree node, int indent)
1626 switch (TREE_CODE (node))
1628 case FUNCFRAME_INFO:
1629 print_node (file, "frame_type", FRAMEINFO_TYPE (node), indent + 4);
1630 break;
1632 default:
1633 break;
1637 /* Return which tree structure is used by NODE, or TS_D_GENERIC if NODE
1638 is one of the language-independent trees. */
1640 d_tree_node_structure_enum
1641 d_tree_node_structure (lang_tree_node *t)
1643 switch (TREE_CODE (&t->generic))
1645 case IDENTIFIER_NODE:
1646 return TS_D_IDENTIFIER;
1648 case FUNCFRAME_INFO:
1649 return TS_D_FRAMEINFO;
1651 default:
1652 return TS_D_GENERIC;
1656 /* Allocate and return a lang specific structure for the frontend type. */
1658 struct lang_type *
1659 build_lang_type (Type *t)
1661 struct lang_type *lt = ggc_cleared_alloc <struct lang_type> ();
1662 lt->type = t;
1663 return lt;
1666 /* Allocate and return a lang specific structure for the frontend decl. */
1668 struct lang_decl *
1669 build_lang_decl (Declaration *d)
1671 /* For compiler generated run-time typeinfo, a lang_decl is allocated even if
1672 there's no associated frontend symbol to refer to (yet). If the symbol
1673 appears later in the compilation, then the slot will be re-used. */
1674 if (d == NULL)
1675 return ggc_cleared_alloc <struct lang_decl> ();
1677 struct lang_decl *ld = (d->csym) ? DECL_LANG_SPECIFIC (d->csym) : NULL;
1678 if (ld == NULL)
1679 ld = ggc_cleared_alloc <struct lang_decl> ();
1681 if (ld->decl == NULL)
1682 ld->decl = d;
1684 return ld;
1687 /* Implements the lang_hooks.dup_lang_specific_decl routine for language D.
1688 Replace the DECL_LANG_SPECIFIC field of NODE with a copy. */
1690 static void
1691 d_dup_lang_specific_decl (tree node)
1693 if (!DECL_LANG_SPECIFIC (node))
1694 return;
1696 struct lang_decl *ld = ggc_alloc <struct lang_decl> ();
1697 memcpy (ld, DECL_LANG_SPECIFIC (node), sizeof (struct lang_decl));
1698 DECL_LANG_SPECIFIC (node) = ld;
1701 /* This preserves trees we create from the garbage collector. */
1703 static GTY(()) tree d_keep_list = NULL_TREE;
1705 void
1706 d_keep (tree t)
1708 d_keep_list = tree_cons (NULL_TREE, t, d_keep_list);
1711 /* Implements the lang_hooks.eh_personality routine for language D.
1712 Return the GDC personality function decl. */
1714 static GTY(()) tree d_eh_personality_decl;
1716 static tree
1717 d_eh_personality (void)
1719 if (!d_eh_personality_decl)
1720 d_eh_personality_decl = build_personality_function ("gdc");
1722 return d_eh_personality_decl;
1725 /* Implements the lang_hooks.eh_runtime_type routine for language D. */
1727 static tree
1728 d_build_eh_runtime_type (tree type)
1730 Type *t = TYPE_LANG_FRONTEND (type);
1731 gcc_assert (t != NULL);
1732 t = t->toBasetype ();
1734 ClassDeclaration *cd = t->isTypeClass ()->sym;
1735 tree decl;
1737 if (cd->isCPPclass ())
1738 decl = get_cpp_typeinfo_decl (cd);
1739 else
1740 decl = get_classinfo_decl (cd);
1742 return convert (ptr_type_node, build_address (decl));
1745 /* Implements the lang_hooks.enum_underlying_base_type routine for language D.
1746 Returns the underlying type of the given enumeration TYPE. */
1748 static tree
1749 d_enum_underlying_base_type (const_tree type)
1751 gcc_assert (TREE_CODE (type) == ENUMERAL_TYPE);
1752 return TREE_TYPE (type);
1755 /* Definitions for our language-specific hooks. */
1757 #undef LANG_HOOKS_NAME
1758 #undef LANG_HOOKS_INIT
1759 #undef LANG_HOOKS_INIT_TS
1760 #undef LANG_HOOKS_INIT_OPTIONS
1761 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1762 #undef LANG_HOOKS_OPTION_LANG_MASK
1763 #undef LANG_HOOKS_HANDLE_OPTION
1764 #undef LANG_HOOKS_POST_OPTIONS
1765 #undef LANG_HOOKS_PARSE_FILE
1766 #undef LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
1767 #undef LANG_HOOKS_ATTRIBUTE_TABLE
1768 #undef LANG_HOOKS_GET_ALIAS_SET
1769 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1770 #undef LANG_HOOKS_BUILTIN_FUNCTION
1771 #undef LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE
1772 #undef LANG_HOOKS_REGISTER_BUILTIN_TYPE
1773 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
1774 #undef LANG_HOOKS_GIMPLIFY_EXPR
1775 #undef LANG_HOOKS_CLASSIFY_RECORD
1776 #undef LANG_HOOKS_TREE_SIZE
1777 #undef LANG_HOOKS_PRINT_XNODE
1778 #undef LANG_HOOKS_DUP_LANG_SPECIFIC_DECL
1779 #undef LANG_HOOKS_EH_PERSONALITY
1780 #undef LANG_HOOKS_EH_RUNTIME_TYPE
1781 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
1782 #undef LANG_HOOKS_PUSHDECL
1783 #undef LANG_HOOKS_GETDECLS
1784 #undef LANG_HOOKS_GLOBAL_BINDINGS_P
1785 #undef LANG_HOOKS_TYPE_FOR_MODE
1786 #undef LANG_HOOKS_TYPE_FOR_SIZE
1787 #undef LANG_HOOKS_TYPE_PROMOTES_TO
1789 #define LANG_HOOKS_NAME "GNU D"
1790 #define LANG_HOOKS_INIT d_init
1791 #define LANG_HOOKS_INIT_TS d_init_ts
1792 #define LANG_HOOKS_INIT_OPTIONS d_init_options
1793 #define LANG_HOOKS_INIT_OPTIONS_STRUCT d_init_options_struct
1794 #define LANG_HOOKS_OPTION_LANG_MASK d_option_lang_mask
1795 #define LANG_HOOKS_HANDLE_OPTION d_handle_option
1796 #define LANG_HOOKS_POST_OPTIONS d_post_options
1797 #define LANG_HOOKS_PARSE_FILE d_parse_file
1798 #define LANG_HOOKS_COMMON_ATTRIBUTE_TABLE d_langhook_common_attribute_table
1799 #define LANG_HOOKS_ATTRIBUTE_TABLE d_langhook_attribute_table
1800 #define LANG_HOOKS_GET_ALIAS_SET d_get_alias_set
1801 #define LANG_HOOKS_TYPES_COMPATIBLE_P d_types_compatible_p
1802 #define LANG_HOOKS_BUILTIN_FUNCTION d_builtin_function
1803 #define LANG_HOOKS_BUILTIN_FUNCTION_EXT_SCOPE d_builtin_function_ext_scope
1804 #define LANG_HOOKS_REGISTER_BUILTIN_TYPE d_register_builtin_type
1805 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL d_finish_incomplete_decl
1806 #define LANG_HOOKS_GIMPLIFY_EXPR d_gimplify_expr
1807 #define LANG_HOOKS_CLASSIFY_RECORD d_classify_record
1808 #define LANG_HOOKS_TREE_SIZE d_tree_size
1809 #define LANG_HOOKS_PRINT_XNODE d_print_xnode
1810 #define LANG_HOOKS_DUP_LANG_SPECIFIC_DECL d_dup_lang_specific_decl
1811 #define LANG_HOOKS_EH_PERSONALITY d_eh_personality
1812 #define LANG_HOOKS_EH_RUNTIME_TYPE d_build_eh_runtime_type
1813 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE d_enum_underlying_base_type
1814 #define LANG_HOOKS_PUSHDECL d_pushdecl
1815 #define LANG_HOOKS_GETDECLS d_getdecls
1816 #define LANG_HOOKS_GLOBAL_BINDINGS_P d_global_bindings_p
1817 #define LANG_HOOKS_TYPE_FOR_MODE d_type_for_mode
1818 #define LANG_HOOKS_TYPE_FOR_SIZE d_type_for_size
1819 #define LANG_HOOKS_TYPE_PROMOTES_TO d_type_promotes_to
1821 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1823 #include "gt-d-d-lang.h"
1824 #include "gtype-d.h"