d: Merge dmd, druntime d8e3976a58, phobos 7a6e95688
[official-gcc.git] / gcc / d / dmd / dversion.d
blob2e3b35264dbe2f4e0ddfd25d92c9d69f69ac164f
1 /**
2 * Defines a `Dsymbol` for `version = identifier` and `debug = identifier` statements.
4 * Specification: $(LINK2 https://dlang.org/spec/version.html#version-specification, Version Specification),
5 * $(LINK2 https://dlang.org/spec/version.html#debug_specification, Debug Specification).
7 * Copyright: Copyright (C) 1999-2024 by The D Language Foundation, All Rights Reserved
8 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
9 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
10 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/dversion.d, _dversion.d)
11 * Documentation: https://dlang.org/phobos/dmd_dversion.html
12 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/dversion.d
15 module dmd.dversion;
17 import dmd.arraytypes;
18 import dmd.cond;
19 import dmd.dmodule;
20 import dmd.dscope;
21 import dmd.dsymbol;
22 import dmd.dsymbolsem;
23 import dmd.errors;
24 import dmd.globals;
25 import dmd.identifier;
26 import dmd.location;
27 import dmd.common.outbuffer;
28 import dmd.visitor;
30 /***********************************************************
31 * DebugSymbol's happen for statements like:
32 * debug = identifier;
33 * debug = integer;
35 extern (C++) final class DebugSymbol : Dsymbol
37 uint level;
39 extern (D) this(const ref Loc loc, Identifier ident) @safe
41 super(loc, ident);
44 extern (D) this(const ref Loc loc, uint level) @safe
46 super(loc, null);
47 this.level = level;
50 override DebugSymbol syntaxCopy(Dsymbol s)
52 assert(!s);
53 auto ds = new DebugSymbol(loc, ident);
54 ds.comment = comment;
55 ds.level = level;
56 return ds;
59 override const(char)* toChars() const nothrow
61 if (ident)
62 return ident.toChars();
63 else
65 OutBuffer buf;
66 buf.print(level);
67 return buf.extractChars();
71 override const(char)* kind() const nothrow
73 return "debug";
76 override inout(DebugSymbol) isDebugSymbol() inout
78 return this;
81 override void accept(Visitor v)
83 v.visit(this);
87 /***********************************************************
88 * VersionSymbol's happen for statements like:
89 * version = identifier;
90 * version = integer;
92 extern (C++) final class VersionSymbol : Dsymbol
94 uint level;
96 extern (D) this(const ref Loc loc, Identifier ident) @safe
98 super(loc, ident);
101 extern (D) this(const ref Loc loc, uint level) @safe
103 super(loc, null);
104 this.level = level;
107 override VersionSymbol syntaxCopy(Dsymbol s)
109 assert(!s);
110 auto ds = ident ? new VersionSymbol(loc, ident)
111 : new VersionSymbol(loc, level);
112 ds.comment = comment;
113 return ds;
116 override const(char)* toChars() const nothrow
118 if (ident)
119 return ident.toChars();
120 else
122 OutBuffer buf;
123 buf.print(level);
124 return buf.extractChars();
128 override const(char)* kind() const nothrow
130 return "version";
133 override inout(VersionSymbol) isVersionSymbol() inout
135 return this;
138 override void accept(Visitor v)
140 v.visit(this);