@@ -17,35 +17,40 @@ import dmd.root.filename;
1717import dmd.root.outbuffer;
1818import dmd.identifier;
1919
20+ // / Defines a setting for how compiler warnings and deprecations are handled
2021enum DiagnosticReporting : ubyte
2122{
22- error, // generate an error
23- inform, // generate a warning
24- off, // disable diagnostic
23+ error, // / generate an error
24+ inform, // / generate a warning
25+ off, // / disable diagnostic
2526}
2627
28+ // / How code locations are formatted for diagnostic reporting
2729enum MessageStyle : ubyte
2830{
29- digitalmars, // filename.d(line): message
30- gnu, // filename.d:line: message, see https://www.gnu.org/prep/standards/html_node/Errors.html
31+ digitalmars, // / filename.d(line): message
32+ gnu, // / filename.d:line: message, see https://www.gnu.org/prep/standards/html_node/Errors.html
3133}
3234
35+ // / In which context checks for assertions, contracts, bounds checks etc. are enabled
3336enum CHECKENABLE : ubyte
3437{
35- _default, // initial value
36- off, // never do checking
37- on, // always do checking
38- safeonly, // do checking only in @safe functions
38+ _default, // / initial value
39+ off, // / never do checking
40+ on, // / always do checking
41+ safeonly, // / do checking only in @safe functions
3942}
4043
44+ // / What should happend when an assertion fails
4145enum CHECKACTION : ubyte
4246{
43- D, // call D assert on failure
44- C, // call C assert on failure
45- halt, // cause program halt on failure
46- context, // call D assert with the error context on failure
47+ D, // / call D assert on failure
48+ C, // / call C assert on failure
49+ halt, // / cause program halt on failure
50+ context, // / call D assert with the error context on failure
4751}
4852
53+ // / Position Indepent Code setting
4954enum PIC : ubyte
5055{
5156 fixed, // / located at a specific address
@@ -67,6 +72,7 @@ enum JsonFieldFlags : uint
6772 semantics = (1 << 3 ),
6873}
6974
75+ // / Version of C++ standard to support
7076enum CppStdRevision : uint
7177{
7278 cpp98 = 1997_11,
@@ -92,7 +98,7 @@ enum FeatureState : byte
9298 enabled = 1 // / Specified as `-preview=`
9399}
94100
95- // Put command line switches in here
101+ // / Put command line switches in here
96102extern (C++ ) struct Param
97103{
98104 bool obj = true ; // write object file
@@ -269,38 +275,50 @@ enum hdr_ext = "di"; // for D 'header' import files
269275enum json_ext = " json" ; // for JSON files
270276enum map_ext = " map" ; // for .map files
271277
278+ /**
279+ * Collection of global compiler settings and global state used by the frontend
280+ */
272281extern (C++ ) struct Global
273282{
274- const (char )[] inifilename;
283+ const (char )[] inifilename; // / filename of configuration file as given by `-conf=`, or default value
275284
276285 string copyright = " Copyright (C) 1999-2021 by The D Language Foundation, All Rights Reserved" ;
277286 string written = " written by Walter Bright" ;
278287
279- Array! (const (char )* )* path; // Array of char*'s which form the import lookup path
280- Array! (const (char )* )* filePath; // Array of char*'s which form the file import lookup path
288+ Array! (const (char )* )* path; // / Array of char*'s which form the import lookup path
289+ Array! (const (char )* )* filePath; // / Array of char*'s which form the file import lookup path
281290
282291 private enum string _version = import (" VERSION" );
283292 private enum uint _versionNumber = parseVersionNumber(_version);
284293
285- const (char )[] vendor; // Compiler backend name
294+ const (char )[] vendor; / / / Compiler backend name
286295
287- Param params;
288- uint errors; // number of errors reported so far
289- uint warnings; // number of warnings reported so far
290- uint gag; // !=0 means gag reporting of errors & warnings
291- uint gaggedErrors; // number of errors reported while gagged
292- uint gaggedWarnings; // number of warnings reported while gagged
296+ Param params; // / command line parameters
297+ uint errors; // / number of errors reported so far
298+ uint warnings; // / number of warnings reported so far
299+ uint gag; // / !=0 means gag reporting of errors & warnings
300+ uint gaggedErrors; // / number of errors reported while gagged
301+ uint gaggedWarnings; // / number of warnings reported while gagged
293302
294- void * console; // opaque pointer to console for controlling text attributes
303+ void * console; // / opaque pointer to console for controlling text attributes
295304
296- Array! Identifier* versionids; // command line versions and predefined versions
297- Array! Identifier* debugids; // command line debug versions and predefined versions
305+ Array! Identifier* versionids; / / / command line versions and predefined versions
306+ Array! Identifier* debugids; / / / command line debug versions and predefined versions
298307
299- enum recursionLimit = 500 ; // number of recursive template expansions before abort
308+ enum recursionLimit = 500 ; // / number of recursive template expansions before abort
300309
301310 nothrow :
302311
303- /* Start gagging. Return the current number of gagged errors
312+ /**
313+ * Start ignoring compile errors instead of reporting them.
314+ *
315+ * Used for speculative compilation like `__traits(compiles, XXX)`, but also internally
316+ * to e.g. try out an `alias this` rewrite without comitting to it.
317+ *
318+ * Works like a stack, so N calls to `startGagging` should be paired with N
319+ * calls to `endGagging`.
320+ *
321+ * Returns: the current number of gagged errors, which should later be passed to `endGagging`
304322 */
305323 extern (C++ ) uint startGagging()
306324 {
@@ -309,8 +327,12 @@ extern (C++) struct Global
309327 return gaggedErrors;
310328 }
311329
312- /* End gagging, restoring the old gagged state.
313- * Return true if errors occurred while gagged.
330+ /**
331+ * Stop gagging, restoring the old gagged state before the most recent call to `startGagging`.
332+ *
333+ * Params:
334+ * oldGagged = the previous number of errors, as returned by `startGagging`
335+ * Returns: true if errors occurred while gagged.
314336 */
315337 extern (C++ ) bool endGagging(uint oldGagged)
316338 {
@@ -323,9 +345,10 @@ extern (C++) struct Global
323345 return anyErrs;
324346 }
325347
326- /* Increment the error count to record that an error
327- * has occurred in the current context. An error message
328- * may or may not have been printed.
348+ /**
349+ * Increment the error count to record that an error has occurred in the current context.
350+ *
351+ * An error message may or may not have been printed.
329352 */
330353 extern (C++ ) void increaseErrorCount()
331354 {
@@ -453,16 +476,22 @@ version (DMDLIB)
453476 version = LocOffset;
454477}
455478
456- // file location
479+ /**
480+ A source code location
481+
482+ Used for error messages, `__FILE__` and `__LINE__` tokens, `__traits(getLocation, XXX)`,
483+ debug info etc.
484+ */
457485struct Loc
458486{
459- const (char )* filename; // either absolute or relative to cwd
460- uint linnum;
461- uint charnum;
487+ // / zero-terminated filename string, either absolute or relative to cwd
488+ const (char )* filename;
489+ uint linnum; // / line number, starting from 1
490+ uint charnum; // / utf8 code unit index relative to start of line, starting from 1
462491 version (LocOffset)
463- uint fileOffset;
492+ uint fileOffset; // / utf8 code unit index relative to start of file, starting from 0
464493
465- static immutable Loc initial; // / use for default initialization of const ref Loc's
494+ static immutable Loc initial; // / use for default initialization of const ref Loc's
466495
467496nothrow :
468497 extern (D ) this (const (char )* filename, uint linnum, uint charnum) pure
@@ -509,10 +538,12 @@ nothrow:
509538 return buf.extractChars();
510539 }
511540
512- /* Checks for equivalence,
513- * a) comparing the filename contents (not the pointer), case-
514- * insensitively on Windows, and
515- * b) ignoring charnum if `global.params.showColumns` is false.
541+ /**
542+ * Checks for equivalence by comparing the filename contents (not the pointer) and character location.
543+ *
544+ * Note:
545+ * - Uses case-insensitive comparison on Windows
546+ * - Ignores `charnum` if `global.params.showColumns` is false.
516547 */
517548 extern (C++ ) bool equals(ref const (Loc) loc) const
518549 {
@@ -521,7 +552,8 @@ nothrow:
521552 FileName.equals(filename, loc.filename);
522553 }
523554
524- /* opEquals() / toHash() for AA key usage:
555+ /**
556+ * `opEquals()` / `toHash()` for AA key usage
525557 *
526558 * Compare filename contents (case-sensitively on Windows too), not
527559 * the pointer - a static foreach loop repeatedly mixing in a mixin
@@ -538,6 +570,7 @@ nothrow:
538570 (filename && loc.filename && strcmp(filename, loc.filename) == 0 ));
539571 }
540572
573+ // / ditto
541574 extern (D ) size_t toHash() const @trusted pure nothrow
542575 {
543576 import dmd.root.string : toDString;
@@ -558,6 +591,9 @@ nothrow:
558591 }
559592}
560593
594+ // / A linkage attribute as defined by `extern(XXX)`
595+ // /
596+ // / https://dlang.org/spec/attribute.html#linkage
561597enum LINK : ubyte
562598{
563599 default_,
@@ -569,28 +605,34 @@ enum LINK : ubyte
569605 system,
570606}
571607
608+ // / Whether to mangle an external aggregate as a struct or class, as set by `extern(C++, struct)`
572609enum CPPMANGLE : ubyte
573610{
574- def,
575- asStruct,
576- asClass,
611+ def, // / default
612+ asStruct, // / `extern(C++, struct)`
613+ asClass, // / `extern(C++, class)`
577614}
578615
616+ // / Function match levels
617+ // /
618+ // / https://dlang.org/spec/function.html#function-overloading
579619enum MATCH : int
580620{
581- nomatch, // no match
582- convert, // match with conversions
583- constant, // match with conversion to const
584- exact, // exact match
621+ nomatch, // / no match
622+ convert, // / match with conversions
623+ constant, // / match with conversion to const
624+ exact, // / exact match
585625}
586626
627+ // / Inline setting as defined by `pragma(inline, XXX)`
587628enum PINLINE : ubyte
588629{
589- default_, // as specified on the command line
590- never, // never inline
591- always, // always inline
630+ default_, / / / as specified on the command line
631+ never, / / / never inline
632+ always, / / / always inline
592633}
593634
594635alias StorageClass = uinteger_t;
595636
637+ // / Collection of global state
596638extern (C++ ) __gshared Global global;
0 commit comments