Created
September 6, 2021 23:24
-
-
Save UplinkCoder/ba2b70b38d54f039a8d1a1bde84d0468 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import core.reflect.reflect; | |
| import core.reflect.dscope; | |
| import core.internal.string : unsignedToTempString; | |
| import core.stdc.stdio; | |
| import std.stdio; | |
| import Iobject = object; | |
| pragma(msg, (const ClassDeclaration cd) { | |
| string result; | |
| result ~= "ClassDeclaration {\n"; | |
| result ~= " name: " ~ cd.name ~ "\n"; | |
| result ~= " location:\n"; | |
| result ~= " {" ~ cd.location.filename ~ ":" ~ unsignedToTempString(cd.location.line) ~ "}\n"; | |
| result ~= " fields: {\n"; | |
| ClassDeclaration[] baseStack; | |
| for(auto base = cast()cd.base; base; base = base.base) | |
| { | |
| baseStack ~= base; | |
| } | |
| foreach_reverse(base;baseStack) | |
| { | |
| result ~= "//fields of: " ~ base.name ~ "\n"; | |
| foreach(f;base.fields) | |
| { | |
| result ~= " " ~ f.type.identifier ~" " ~ f.name ~ | |
| " {" ~ unsignedToTempString(f.offset) ~ "}" ~ ";\n"; | |
| } | |
| } | |
| result ~= "//fields of: " ~ cd.name ~ "\n"; | |
| foreach(f;cd.fields) | |
| { | |
| result ~= " " ~ f.type.identifier ~" " ~ f.name ~ | |
| "// at offset {" ~ unsignedToTempString(f.offset) ~ "}" ~ ";\n"; | |
| } | |
| result ~= " }\n"; | |
| result ~= "}\n"; | |
| return result; | |
| } (cast(immutable ClassDeclaration) nodeFromName("StructDeclaration", ReflectFlags.NoParent | ReflectFlags.NoFunctionbody))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment