Overloads not returning appropriate info. [Field reflunkory]
Alex
AJ at gmail.com
Sat Apr 6 12:20:28 UTC 2019
On Friday, 5 April 2019 at 15:38:18 UTC, Adam D. Ruppe wrote:
> BTW `T.stringof` is usually a bug waiting to happen. You are
> using mixin in a lot of places where you shouldn't be and this
> is going to lead to name conflicts, import problems, and more.
> Just use `T`.
>
> If you need a member, use __traits(getMember, T, "name").
I fixed the parameter info issue and rewrote a large portion of
the code to work better, the main problem was that I was doing
static foreach (f; typeof(__traits(getOverloads, T, m)))
but now I get
Error: variable `std.traits.ParameterDefaults!(foo).Get!1u.Get`
only parameters or stack based variables can be `inout`
sParameterReflection("y", "inout(float)", "void", "void",
sStorageClass(false, false, false, false, false, false)),
for
pure nothrow @nogc @safe int(int x, inout(float) y = 4.00000F,
double x7 = 434.3)
inout clearly has a default value but an error is given. All
other default values are returning correctly.
static if (__traits(compiles, typeof(ParameterDefaults!T[k])))
{
enum pd = ParameterDefaults!T[k];
alias dt = typeof(pd);
}
else
{
alias dt = void;
alias pd = void;
}
t.Parameters ~=
sParameterReflection(ParameterIdentifierTuple!T[k], a.stringof,
pd.stringof, dt.stringof);
Without the __traits compiles the error occurs in the enum by
simply taking ParameterDefaults.
---------------------------------------------------
The mixin code with T are to build compound names. I never use a
mixin for just accessing T alone as far as I know, you are going
to have to be more clear on what you are talking about here.
probably 90% of the mixins are of the form
mixin(`Protection = __traits(getProtection,
(`~T.stringof~`).`~name~`);`);
Where I have to build the type info, such things as
Protection = __traits(getProtection, T.name);
will definitely not work.
-------------------------
This is now the output of the code and everything seems to
basically work now except the above issue.
Id = cDerived
TypeName = cDerived!int
FullName = mModel.cDerived!(int)
ModuleName = mModel
MangledName = C6mModel__T8cDerivedTiZQm
Protection = public
Body =
Uses = []
Attributes = [
sAttributeReflection("fdsa", "string"),
sAttributeReflection("8", "int")
]
IsNested = false
IsInnerClass = false
HasUnsharedAliasing = true
HasNested = false
HasIndirections = true
HasElaborateDestructor = false
HasElaborateCopyConstructor = false
HasElaborateAssign = false
HasAliasing = true
TypeParameters = []
AliasThis = [sTypeReflection("type", "cType")]
NestedAggregates = []
DerivedClasses = []
Fields = [
Id = type
TypeName = cDerived!int.type
FullName = mModel.cDerived!(int).type
ModuleName = mModel
MangledName = C6mModel__T8cDerivedTiZQm
Protection = public
Body =
Uses = []
Attributes = []
DType = field
,
Id = testField1
TypeName = cDerived!int.testField1
FullName = mModel.cDerived!(int).testField1
ModuleName = mModel
MangledName = C6mModel__T8cDerivedTiZQm
Protection = public
Body =
Uses = []
Attributes = [sAttributeReflection("XXXRRERES", "string")]
DType = field
,
Id = testField2
TypeName = cDerived!int.testField2
FullName = mModel.cDerived!(int).testField2
ModuleName = mModel
MangledName = C6mModel__T8cDerivedTiZQm
Protection = private
Body =
Uses = []
Attributes = [sAttributeReflection("XXXRRERES4", "string")]
DType = field
]
Methods = [
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFZi
Protection = public
Body =
Uses = []
Attributes = [sAttributeReflection("A", "string")]
Signature = int()
NumArgs = 0
Linkage = D
ReturnType = int
Parameters = []
Overloads = [
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFNaNbNiNfiNgfdZi
Protection = private
Body =
Uses = []
Attributes = [sAttributeReflection("B", "string")]
DType = function
Signature = pure nothrow @nogc @safe int(int x, inout(float) y
= 4.00000F, double x7 = 434.3)
NumArgs = 3
Linkage = D
ReturnType = int
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "inout(float)", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("x7", "double", "void", "void",
sStorageClass(false, false, false, false, false, false))
]
,
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFiKdlfZi
Protection = public
Body =
Uses = []
Attributes = [
sAttributeReflection("attr!string(\"test\", 432)",
"attr!string"),
sAttributeReflection("4", "int")
]
DType = function
Signature = int(int x, ref double y, long q = 3L, float z =
43234.3F)
NumArgs = 4
Linkage = D
ReturnType = int
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "double", "void", "void",
sStorageClass(false, false, false, true, false, false)),
sParameterReflection("q", "long", "3L", "long",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("z", "float", "43234.3F", "float",
sStorageClass(false, false, false, false, false, false))
]
]
DType = delegate
,
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFZi
Protection = public
Body =
Uses = []
Attributes = [sAttributeReflection("A", "string")]
Signature = int()
NumArgs = 0
Linkage = D
ReturnType = int
Parameters = []
Overloads = [
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFNaNbNiNfiNgfdZi
Protection = private
Body =
Uses = []
Attributes = [sAttributeReflection("B", "string")]
DType = function
Signature = pure nothrow @nogc @safe int(int x, inout(float) y
= 4.00000F, double x7 = 434.3)
NumArgs = 3
Linkage = D
ReturnType = int
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "inout(float)", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("x7", "double", "void", "void",
sStorageClass(false, false, false, false, false, false))
]
,
Id = foo
TypeName =
FullName = mModel.cDerived!(int).foo
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm3fooMFiKdlfZi
Protection = public
Body =
Uses = []
Attributes = [
sAttributeReflection("attr!string(\"test\", 432)",
"attr!string"),
sAttributeReflection("4", "int")
]
DType = function
Signature = int(int x, ref double y, long q = 3L, float z =
43234.3F)
NumArgs = 4
Linkage = D
ReturnType = int
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "double", "void", "void",
sStorageClass(false, false, false, true, false, false)),
sParameterReflection("q", "long", "3L", "long",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("z", "float", "43234.3F", "float",
sStorageClass(false, false, false, false, false, false))
]
]
DType = delegate
,
Id = ValueProp
TypeName =
FullName = mModel.cDerived!(int).ValueProp
ModuleName = mModel
MangledName = _D6mModel__T8cDerivedTiZQm9ValuePropMFNdZi
Protection = public
Body =
Uses = []
Attributes = [sAttributeReflection("VP att", "string")]
Signature = @property int()
NumArgs = 0
Linkage = D
ReturnType = int
Parameters = []
Overloads = []
DType = delegate
]
InheritedInterfaces = [
Id = iX
TypeName = iX
FullName = mModel.iX
ModuleName = mModel
MangledName = C6mModel2iX
Protection = public
Body =
Uses = []
Attributes = []
IsNested = false
IsInnerClass = false
HasUnsharedAliasing = true
HasNested = false
HasIndirections = true
HasElaborateDestructor = false
HasElaborateCopyConstructor = false
HasElaborateAssign = false
HasAliasing = true
TypeParameters = []
AliasThis = []
NestedAggregates = []
DerivedClasses = []
Fields = [
Id =
TypeName =
FullName =
ModuleName =
MangledName =
Protection =
Body =
Uses = []
Attributes = []
DType = field
]
Methods = []
DType = interface
InheritedInterfaces = []
,
Id = iY
TypeName = iY
FullName = mModel.iY
ModuleName = mModel
MangledName = C6mModel2iY
Protection = public
Body =
Uses = []
Attributes = []
IsNested = false
IsInnerClass = false
HasUnsharedAliasing = true
HasNested = false
HasIndirections = true
HasElaborateDestructor = false
HasElaborateCopyConstructor = false
HasElaborateAssign = false
HasAliasing = true
TypeParameters = []
AliasThis = []
NestedAggregates = []
DerivedClasses = []
Fields = [
Id =
TypeName =
FullName =
ModuleName =
MangledName =
Protection =
Body =
Uses = []
Attributes = []
DType = field
]
Methods = []
DType = interface
InheritedInterfaces = []
]
DType = class
IsAbstract = false
Alignment = 8
InheritedClasses = [
Id = cBase
TypeName = cBase
FullName = mModel.cBase
ModuleName = mModel
MangledName = C6mModel5cBase
Protection = public
Body =
Uses = []
Attributes = []
IsNested = false
IsInnerClass = false
HasUnsharedAliasing = true
HasNested = false
HasIndirections = true
HasElaborateDestructor = false
HasElaborateCopyConstructor = false
HasElaborateAssign = false
HasAliasing = true
TypeParameters = []
AliasThis = []
NestedAggregates = []
DerivedClasses = []
Fields = [
Id = testField
TypeName = cBase.testField
FullName = mModel.cBase.testField
ModuleName = mModel
MangledName = C6mModel5cBase
Protection = public
Body =
Uses = []
Attributes = []
DType = field
]
Methods = [
Id = fooBase
TypeName =
FullName = mModel.cBase.fooBase
ModuleName = mModel
MangledName = _D6mModel5cBase7fooBaseMFCQy5iBaseZCQBiQBe
Protection = public
Body =
Uses = []
Attributes = []
Signature = cBase(iBase c)
NumArgs = 1
Linkage = D
ReturnType = cBase
Parameters = [
sParameterReflection("c", "iBase", "void", "void",
sStorageClass(false, false, false, false, false, false))
]
Overloads = []
DType = delegate
]
InheritedInterfaces = [
Id = iBase
TypeName = iBase
FullName = mModel.iBase
ModuleName = mModel
MangledName = C6mModel5iBase
Protection = public
Body =
Uses = []
Attributes = [
sAttributeReflection("fdsa", "string"),
sAttributeReflection("4", "int")
]
IsNested = false
IsInnerClass = false
HasUnsharedAliasing = true
HasNested = false
HasIndirections = true
HasElaborateDestructor = false
HasElaborateCopyConstructor = false
HasElaborateAssign = false
HasAliasing = true
TypeParameters = []
AliasThis = []
NestedAggregates = []
DerivedClasses = []
Fields = [
Id =
TypeName =
FullName =
ModuleName =
MangledName =
Protection =
Body =
Uses = []
Attributes = []
DType = field
]
Methods = [
Id = fooBase
TypeName =
FullName = mModel.iBase.fooBase
ModuleName = mModel
MangledName = _D6mModel5iBase7fooBaseMFCQyQtZQg
Protection = public
Body =
Uses = []
Attributes = []
Signature = iBase(iBase)
NumArgs = 1
Linkage = D
ReturnType = iBase
Parameters = [
sParameterReflection("", "iBase", "void", "void",
sStorageClass(false, false, false, false, false, false))
]
Overloads = []
DType = delegate
]
DType = interface
InheritedInterfaces = []
]
DType = class
IsAbstract = false
Alignment = 4
InheritedClasses = [Object]
]
Id = bar
TypeName =
FullName = mMain.bar
ModuleName = mMain
MangledName = _D5mMain3barFiKdfZv
Protection = public
Body =
Uses = []
Attributes = [
sAttributeReflection("attr!string(\"test\", 432)",
"attr!string"),
sAttributeReflection("4", "int")
]
DType = function
Signature = void(int x, ref double y, float z = 43234.3F)
NumArgs = 3
Linkage = D
ReturnType = void
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "double", "void", "void",
sStorageClass(false, false, false, true, false, false)),
sParameterReflection("z", "float", "43234.3F", "float",
sStorageClass(false, false, false, false, false, false))
]
Overloads = [
Id = bar
TypeName =
FullName = mMain.bar
ModuleName = mMain
MangledName = _D5mMain3barFiKdlfZv
Protection = public
Body =
Uses = []
Attributes = [sAttributeReflection("564", "int")]
DType = function
Signature = void(int x, ref double y, long q = 3L, float z =
43234.3F)
NumArgs = 4
Linkage = D
ReturnType = void
Parameters = [
sParameterReflection("x", "int", "void", "void",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("y", "double", "void", "void",
sStorageClass(false, false, false, true, false, false)),
sParameterReflection("q", "long", "3L", "long",
sStorageClass(false, false, false, false, false, false)),
sParameterReflection("z", "float", "43234.3F", "float",
sStorageClass(false, false, false, false, false, false))
]
]
More information about the Digitalmars-d-learn
mailing list