Skip to content

Instantly share code, notes, and snippets.

@UplinkCoder
Created September 6, 2021 23:24
Show Gist options
  • Select an option

  • Save UplinkCoder/ba2b70b38d54f039a8d1a1bde84d0468 to your computer and use it in GitHub Desktop.

Select an option

Save UplinkCoder/ba2b70b38d54f039a8d1a1bde84d0468 to your computer and use it in GitHub Desktop.
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