| 1 |
/** |
| 2 |
* Provide the root object that AST classes in dmd inherit from. |
| 3 |
* |
| 4 |
* Copyright: Copyright (C) 1999-2025 by The D Language Foundation, All Rights Reserved |
| 5 |
* Authors: Walter Bright, https://www.digitalmars.com |
| 6 |
* License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0) |
| 7 |
* Source: $(LINK2 https://github.com/dlang/dmd/blob/master/compiler/src/dmd/rootobject.d, _rootobject.d) |
| 8 |
* Documentation: https://dlang.org/phobos/dmd_rootobject.html |
| 9 |
* Coverage: https://codecov.io/gh/dlang/dmd/src/master/compiler/src/dmd/rootobject.d |
| 10 |
*/ |
| 11 |
|
| 12 |
module dmd.rootobject; |
| 13 |
|
| 14 |
/*********************************************************** |
| 15 |
*/ |
| 16 |
|
| 17 |
enum DYNCAST : int |
| 18 |
{ |
| 19 |
object, |
| 20 |
expression, |
| 21 |
dsymbol, |
| 22 |
type, |
| 23 |
identifier, |
| 24 |
tuple, |
| 25 |
parameter, |
| 26 |
statement, |
| 27 |
condition, |
| 28 |
templateparameter, |
| 29 |
initializer, |
| 30 |
} |
| 31 |
|
| 32 |
/*********************************************************** |
| 33 |
*/ |
| 34 |
|
| 35 |
extern (C++) class RootObject |
| 36 |
{ |
| 37 |
this() nothrow pure @nogc @safe scope |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
bool equals(const RootObject o) const |
| 42 |
{ |
| 43 |
return o is this; |
| 44 |
} |
| 45 |
|
| 46 |
const(char)* toChars() const |
| 47 |
{ |
| 48 |
assert(0); |
| 49 |
} |
| 50 |
|
| 51 |
/// |
| 52 |
extern(D) const(char)[] toString() const |
| 53 |
{ |
| 54 |
import core.stdc.string : strlen; |
| 55 |
auto p = this.toChars(); |
| 56 |
return p[0 .. strlen(p)]; |
| 57 |
} |
| 58 |
|
| 59 |
DYNCAST dyncast() const nothrow pure @nogc @safe |
| 60 |
{ |
| 61 |
return DYNCAST.object; |
| 62 |
} |
| 63 |
} |