Move PREFERRED_DEBUGGING_TYPE define in pa64-hpux.h to pa.h
[official-gcc.git] / gcc / d / d-frontend.cc
blob30fc6d435d082ced26c90cad6839bfde12dcf27d
1 /* d-frontend.cc -- D frontend interface to the gcc back-end.
2 Copyright (C) 2013-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/declaration.h"
24 #include "dmd/expression.h"
25 #include "dmd/module.h"
26 #include "dmd/mtype.h"
27 #include "dmd/scope.h"
29 #include "tree.h"
30 #include "options.h"
31 #include "fold-const.h"
32 #include "diagnostic.h"
34 #include "d-tree.h"
37 /* Implements the Global interface defined by the frontend.
38 Used for managing the state of the current compilation. */
40 Global global;
42 void
43 Global::_init (void)
45 this->mars_ext = "d";
46 this->hdr_ext = "di";
47 this->doc_ext = "html";
48 this->ddoc_ext = "ddoc";
49 this->json_ext = "json";
50 this->obj_ext = "o";
52 this->run_noext = true;
53 this->version = "v"
54 #include "verstr.h"
57 this->stdmsg = stderr;
60 /* Start gagging. Return the current number of gagged errors. */
62 unsigned
63 Global::startGagging (void)
65 this->gag++;
66 return this->gaggedErrors;
69 /* End gagging, restoring the old gagged state. Return true if errors
70 occured while gagged. */
72 bool
73 Global::endGagging (unsigned oldGagged)
75 bool anyErrs = (this->gaggedErrors != oldGagged);
76 this->gag--;
78 /* Restore the original state of gagged errors; set total errors
79 to be original errors + new ungagged errors. */
80 this->errors -= (this->gaggedErrors - oldGagged);
81 this->gaggedErrors = oldGagged;
83 return anyErrs;
86 /* Increment the error count to record that an error has occured in the
87 current context. An error message may or may not have been printed. */
89 void
90 Global::increaseErrorCount (void)
92 if (gag)
93 this->gaggedErrors++;
95 this->errors++;
99 /* Implements the Loc interface defined by the frontend.
100 Used for keeping track of current file/line position in code. */
102 Loc::Loc (const char *filename, unsigned linnum, unsigned charnum)
104 this->linnum = linnum;
105 this->charnum = charnum;
106 this->filename = filename;
109 const char *
110 Loc::toChars (void) const
112 OutBuffer buf;
114 if (this->filename)
115 buf.printf ("%s", this->filename);
117 if (this->linnum)
119 buf.printf (":%u", this->linnum);
120 if (this->charnum)
121 buf.printf (":%u", this->charnum);
124 return buf.extractChars ();
127 bool
128 Loc::equals (const Loc &loc)
130 if (this->linnum != loc.linnum || this->charnum != loc.charnum)
131 return false;
133 if (!FileName::equals (this->filename, loc.filename))
134 return false;
136 return true;
140 /* Implements back-end specific interfaces used by the frontend. */
142 /* Determine if function FD is a builtin one that we can evaluate in CTFE. */
144 BUILTIN
145 isBuiltin (FuncDeclaration *fd)
147 if (fd->builtin != BUILTINunknown)
148 return fd->builtin;
150 maybe_set_intrinsic (fd);
152 return fd->builtin;
155 /* Evaluate builtin D function FD whose argument list is ARGUMENTS.
156 Return result; NULL if cannot evaluate it. */
158 Expression *
159 eval_builtin (Loc loc, FuncDeclaration *fd, Expressions *arguments)
161 if (fd->builtin == BUILTINunimp)
162 return NULL;
164 tree decl = get_symbol_decl (fd);
165 gcc_assert (fndecl_built_in_p (decl)
166 || DECL_INTRINSIC_CODE (decl) != INTRINSIC_NONE);
168 TypeFunction *tf = fd->type->toTypeFunction ();
169 Expression *e = NULL;
170 input_location = make_location_t (loc);
172 tree result = d_build_call (tf, decl, NULL, arguments);
173 result = fold (result);
175 /* Builtin should be successfully evaluated.
176 Will only return NULL if we can't convert it. */
177 if (TREE_CONSTANT (result) && TREE_CODE (result) != CALL_EXPR)
178 e = d_eval_constant_expression (loc, result);
180 return e;
183 /* Build and return typeinfo type for TYPE. */
185 Type *
186 getTypeInfoType (Loc loc, Type *type, Scope *sc)
188 gcc_assert (type->ty != Terror);
189 check_typeinfo_type (loc, sc);
190 create_typeinfo (type, sc ? sc->_module->importedFrom : NULL);
191 return type->vtinfo->type;
194 /* Return an inlined copy of a default argument for a function parameter. */
196 Expression *
197 inlineCopy (Expression *e, Scope *)
199 return e->copy ();