mirror of
https://github.com/esiur/esiur-dart.git
synced 2026-04-03 17:58:21 +00:00
Annotations
This commit is contained in:
@@ -8,19 +8,19 @@ import 'TypeTemplate.dart';
|
||||
|
||||
class ConstantTemplate extends MemberTemplate {
|
||||
final dynamic value;
|
||||
final String? expansion;
|
||||
final String? annotation;
|
||||
final RepresentationType valueType;
|
||||
|
||||
ConstantTemplate(TypeTemplate template, int index, String name,
|
||||
bool inherited, this.valueType, this.value, this.expansion)
|
||||
bool inherited, this.valueType, this.value, this.annotation)
|
||||
: super(template, index, name, inherited) {}
|
||||
|
||||
DC compose() {
|
||||
var name = super.compose();
|
||||
var hdr = inherited ? 0x80 : 0;
|
||||
|
||||
if (expansion != null) {
|
||||
var exp = DC.stringToBytes(expansion!);
|
||||
if (annotation != null) {
|
||||
var exp = DC.stringToBytes(annotation!);
|
||||
hdr |= 0x70;
|
||||
return (BinaryList()
|
||||
..addUint8(hdr)
|
||||
|
||||
@@ -6,7 +6,7 @@ import 'MemberType.dart';
|
||||
import '../../Data/RepresentationType.dart';
|
||||
|
||||
class EventTemplate extends MemberTemplate {
|
||||
final String? expansion;
|
||||
final String? annotation;
|
||||
final bool listenable;
|
||||
final RepresentationType argumentType;
|
||||
|
||||
@@ -17,8 +17,8 @@ class EventTemplate extends MemberTemplate {
|
||||
|
||||
if (listenable) hdr |= 0x8;
|
||||
|
||||
if (expansion != null) {
|
||||
var exp = DC.stringToBytes(expansion as String);
|
||||
if (annotation != null) {
|
||||
var exp = DC.stringToBytes(annotation as String);
|
||||
hdr |= 0x50;
|
||||
return (BinaryList()
|
||||
..addUint8(hdr)
|
||||
@@ -41,6 +41,6 @@ class EventTemplate extends MemberTemplate {
|
||||
|
||||
EventTemplate(TypeTemplate template, int index, String name, bool inherited,
|
||||
this.argumentType,
|
||||
[this.expansion = null, this.listenable = false])
|
||||
[this.annotation = null, this.listenable = false])
|
||||
: super(template, index, name, inherited) {}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'ArgumentTemplate.dart';
|
||||
import '../../Data/RepresentationType.dart';
|
||||
|
||||
class FunctionTemplate extends MemberTemplate {
|
||||
String? expansion;
|
||||
String? annotation;
|
||||
// bool isVoid;
|
||||
|
||||
List<ArgumentTemplate> arguments;
|
||||
@@ -24,8 +24,8 @@ class FunctionTemplate extends MemberTemplate {
|
||||
|
||||
for (var i = 0; i < arguments.length; i++) bl.addDC(arguments[i].compose());
|
||||
|
||||
if (expansion != null) {
|
||||
var exp = DC.stringToBytes(expansion as String);
|
||||
if (annotation != null) {
|
||||
var exp = DC.stringToBytes(annotation as String);
|
||||
bl
|
||||
..addInt32(exp.length)
|
||||
..addDC(exp);
|
||||
@@ -38,6 +38,6 @@ class FunctionTemplate extends MemberTemplate {
|
||||
|
||||
FunctionTemplate(TypeTemplate template, int index, String name,
|
||||
bool inherited, this.arguments, this.returnType,
|
||||
[this.expansion = null])
|
||||
[this.annotation = null])
|
||||
: super(template, index, name, inherited) {}
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ class PropertyTemplate extends MemberTemplate {
|
||||
|
||||
bool recordable;
|
||||
|
||||
String? readExpansion;
|
||||
String? readAnnotation;
|
||||
|
||||
String? writeExpansion;
|
||||
String? writeAnnotation;
|
||||
|
||||
DC compose() {
|
||||
var name = super.compose();
|
||||
@@ -23,9 +23,9 @@ class PropertyTemplate extends MemberTemplate {
|
||||
|
||||
if (inherited) pv |= 0x80;
|
||||
|
||||
if (writeExpansion != null && readExpansion != null) {
|
||||
var rexp = DC.stringToBytes(readExpansion as String);
|
||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
||||
if (writeAnnotation != null && readAnnotation != null) {
|
||||
var rexp = DC.stringToBytes(readAnnotation as String);
|
||||
var wexp = DC.stringToBytes(writeAnnotation as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x38 | pv)
|
||||
..addUint8(name.length)
|
||||
@@ -36,8 +36,8 @@ class PropertyTemplate extends MemberTemplate {
|
||||
..addInt32(rexp.length)
|
||||
..addDC(rexp))
|
||||
.toDC();
|
||||
} else if (writeExpansion != null) {
|
||||
var wexp = DC.stringToBytes(writeExpansion as String);
|
||||
} else if (writeAnnotation != null) {
|
||||
var wexp = DC.stringToBytes(writeAnnotation as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x30 | pv)
|
||||
..addUint8(name.length)
|
||||
@@ -46,8 +46,8 @@ class PropertyTemplate extends MemberTemplate {
|
||||
..addInt32(wexp.length)
|
||||
..addDC(wexp))
|
||||
.toDC();
|
||||
} else if (readExpansion != null) {
|
||||
var rexp = DC.stringToBytes(readExpansion as String);
|
||||
} else if (readAnnotation != null) {
|
||||
var rexp = DC.stringToBytes(readAnnotation as String);
|
||||
return (BinaryList()
|
||||
..addUint8(0x28 | pv)
|
||||
..addUint8(name.length)
|
||||
@@ -67,8 +67,8 @@ class PropertyTemplate extends MemberTemplate {
|
||||
|
||||
PropertyTemplate(TypeTemplate template, int index, String name,
|
||||
bool inherited, this.valueType,
|
||||
[this.readExpansion = null,
|
||||
this.writeExpansion = null,
|
||||
[this.readAnnotation = null,
|
||||
this.writeAnnotation = null,
|
||||
this.recordable = false])
|
||||
: super(template, index, name, inherited) {}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
class TemplateDescriber {
|
||||
final List<Prop>? properties;
|
||||
final List<Evt>? events;
|
||||
@@ -8,6 +7,7 @@ class TemplateDescriber {
|
||||
final String nameSpace;
|
||||
final int version;
|
||||
final Type? parent;
|
||||
final String? annotation;
|
||||
|
||||
const TemplateDescriber(this.nameSpace,
|
||||
{this.parent,
|
||||
@@ -15,7 +15,8 @@ class TemplateDescriber {
|
||||
this.functions,
|
||||
this.events,
|
||||
this.constants,
|
||||
this.version = 0});
|
||||
this.version = 0,
|
||||
this.annotation = null});
|
||||
}
|
||||
|
||||
// class Property<T> {
|
||||
|
||||
@@ -26,6 +26,8 @@ class TypeTemplate {
|
||||
late Guid _classId;
|
||||
Guid? _parentId = null;
|
||||
|
||||
String? _annotation;
|
||||
|
||||
late String _className;
|
||||
List<MemberTemplate> _members = [];
|
||||
List<FunctionTemplate> _functions = [];
|
||||
@@ -40,6 +42,8 @@ class TypeTemplate {
|
||||
|
||||
late DC _content;
|
||||
|
||||
String? get annotation => _annotation;
|
||||
|
||||
DC get content => _content;
|
||||
|
||||
TemplateType get type => _templateType;
|
||||
@@ -155,6 +159,8 @@ class TypeTemplate {
|
||||
|
||||
_version = describer.version;
|
||||
|
||||
_annotation = describer.annotation;
|
||||
|
||||
if (addToWarehouse) Warehouse.putTemplate(this);
|
||||
// _templates.add(template.classId, template);
|
||||
|
||||
@@ -253,10 +259,19 @@ class TypeTemplate {
|
||||
|
||||
// bake it binarily
|
||||
var b = BinaryList()
|
||||
..addUint8(_templateType.index)
|
||||
..addUint8((_annotation != null ? 0x40 : 0x0) | _templateType.index)
|
||||
..addGuid(classId)
|
||||
..addUint8(className.length)
|
||||
..addString(className)
|
||||
..addString(className);
|
||||
|
||||
if (_annotation != null) {
|
||||
var classAnnotationBytes = DC.stringToBytes(_annotation!);
|
||||
b
|
||||
..addUint16(classAnnotationBytes.length)
|
||||
..addDC(classAnnotationBytes);
|
||||
}
|
||||
|
||||
b
|
||||
..addInt32(_version)
|
||||
..addUint16(_members.length);
|
||||
|
||||
@@ -267,219 +282,6 @@ class TypeTemplate {
|
||||
_content = b.toDC();
|
||||
}
|
||||
|
||||
// static Guid getTypeGuid(Type type) => getTypeGuid(type.toString());
|
||||
|
||||
// static Guid getTypeGuid(String typeName)
|
||||
// {
|
||||
// var tn = Encoding.UTF8.GetBytes(typeName);
|
||||
// var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
||||
|
||||
// return new Guid(hash);
|
||||
// }
|
||||
|
||||
// static Type GetElementType(Type type) => type switch
|
||||
// {
|
||||
// { IsArray: true } => type.GetElementType(),
|
||||
// { IsEnum: true } => type.GetEnumUnderlyingType(),
|
||||
// (_) => type
|
||||
// };
|
||||
|
||||
// static TypeTemplate[] GetRuntimeTypes(TypeTemplate template)
|
||||
// {
|
||||
|
||||
// List<TypeTemplate> list = [];
|
||||
|
||||
// list.add(template);
|
||||
|
||||
// var getRuntimeTypes = null;
|
||||
|
||||
// getRuntimeTypes = (TypeTemplate tmp, List<TypeTemplate> bag)
|
||||
// {
|
||||
// if (template.resourceType == null)
|
||||
// return;
|
||||
|
||||
// // functions
|
||||
// tmp.functions.foreach((f){
|
||||
|
||||
// var frtt = Warehouse.GetTemplate(getElementType(f.MethodInfo.ReturnType));
|
||||
// if (frtt != null)
|
||||
// {
|
||||
// if (!bag.Contains(frtt))
|
||||
// {
|
||||
// list.Add(frtt);
|
||||
// getRuntimeTypes(frtt, bag);
|
||||
// }
|
||||
// }
|
||||
|
||||
// var args = f.MethodInfo.GetParameters();
|
||||
|
||||
// for(var i = 0; i < args.Length - 1; i++)
|
||||
// {
|
||||
// var fpt = Warehouse.GetTemplate(GetElementType(args[i].ParameterType));
|
||||
// if (fpt != null)
|
||||
// {
|
||||
// if (!bag.Contains(fpt))
|
||||
// {
|
||||
// bag.Add(fpt);
|
||||
// getRuntimeTypes(fpt, bag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // skip DistributedConnection argument
|
||||
// if (args.Length > 0)
|
||||
// {
|
||||
// var last = args.Last();
|
||||
// if (last.ParameterType != typeof(DistributedConnection))
|
||||
// {
|
||||
// var fpt = Warehouse.GetTemplate(GetElementType(last.ParameterType));
|
||||
// if (fpt != null)
|
||||
// {
|
||||
// if (!bag.Contains(fpt))
|
||||
// {
|
||||
// bag.Add(fpt);
|
||||
// getRuntimeTypes(fpt, bag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// });
|
||||
|
||||
// // properties
|
||||
// foreach (var p in tmp.properties)
|
||||
// {
|
||||
// var pt = Warehouse.GetTemplate(GetElementType(p.PropertyInfo.PropertyType));
|
||||
// if (pt != null)
|
||||
// {
|
||||
// if (!bag.Contains(pt))
|
||||
// {
|
||||
// bag.Add(pt);
|
||||
// getRuntimeTypes(pt, bag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// // events
|
||||
// foreach (var e in tmp.events)
|
||||
// {
|
||||
// var et = Warehouse.GetTemplate(GetElementType(e.EventInfo.EventHandlerType.GenericTypeArguments[0]));
|
||||
|
||||
// if (et != null)
|
||||
// {
|
||||
// if (!bag.Contains(et))
|
||||
// {
|
||||
// bag.Add(et);
|
||||
// getRuntimeTypes(et, bag);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
|
||||
// getRuntimeTypes(template, list);
|
||||
// return list.ToArray();
|
||||
// }
|
||||
|
||||
// @TODO Create template from type
|
||||
// TypeTemplate.fromType(Type type) {
|
||||
|
||||
// }
|
||||
|
||||
/*
|
||||
TypeTemplate(Type type)
|
||||
{
|
||||
|
||||
type = ResourceProxy.GetBaseType(type);
|
||||
|
||||
// set guid
|
||||
|
||||
var typeName = Encoding.UTF8.GetBytes(type.FullName);
|
||||
var hash = SHA256.Create().ComputeHash(typeName).Clip(0, 16);
|
||||
|
||||
classId = new Guid(hash);
|
||||
className = type.FullName;
|
||||
|
||||
|
||||
#if NETSTANDARD1_5
|
||||
PropertyInfo[] propsInfo = type.GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetTypeInfo().GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetTypeInfo().GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
|
||||
#else
|
||||
PropertyInfo[] propsInfo = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
EventInfo[] eventsInfo = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
MethodInfo[] methodsInfo = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
|
||||
#endif
|
||||
|
||||
//byte currentIndex = 0;
|
||||
|
||||
byte i = 0;
|
||||
|
||||
foreach (var pi in propsInfo)
|
||||
{
|
||||
var ps = (ResourceProperty[])pi.GetCustomAttributes(typeof(ResourceProperty), true);
|
||||
if (ps.Length > 0)
|
||||
{
|
||||
var pt = new PropertyTemplate(this, i++, pi.Name, ps[0].ReadExpansion, ps[0].WriteExpansion, ps[0].Storage);
|
||||
pt.Info = pi;
|
||||
properties.Add(pt);
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
|
||||
foreach (var ei in eventsInfo)
|
||||
{
|
||||
var es = (ResourceEvent[])ei.GetCustomAttributes(typeof(ResourceEvent), true);
|
||||
if (es.Length > 0)
|
||||
{
|
||||
var et = new EventTemplate(this, i++, ei.Name, es[0].Expansion);
|
||||
events.Add(et);
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
foreach (MethodInfo mi in methodsInfo)
|
||||
{
|
||||
var fs = (ResourceFunction[])mi.GetCustomAttributes(typeof(ResourceFunction), true);
|
||||
if (fs.Length > 0)
|
||||
{
|
||||
var ft = new FunctionTemplate(this, i++, mi.Name, mi.ReturnType == typeof(void), fs[0].Expansion);
|
||||
functions.Add(ft);
|
||||
}
|
||||
}
|
||||
|
||||
// append signals
|
||||
for (i = 0; i < events.Count; i++)
|
||||
members.Add(events[i]);
|
||||
// append slots
|
||||
for (i = 0; i < functions.Count; i++)
|
||||
members.Add(functions[i]);
|
||||
// append properties
|
||||
for (i = 0; i < properties.Count; i++)
|
||||
members.Add(properties[i]);
|
||||
|
||||
// bake it binarily
|
||||
var b = new BinaryList();
|
||||
b.AddGuid(classId)
|
||||
.AddUInt8((byte)className.Length)
|
||||
.AddString(className)
|
||||
.AddInt32(version)
|
||||
.AddUInt16((ushort)members.Count);
|
||||
|
||||
|
||||
foreach (var ft in functions)
|
||||
b.AddUInt8Array(ft.Compose());
|
||||
foreach (var pt in properties)
|
||||
b.AddUInt8Array(pt.Compose());
|
||||
foreach (var et in events)
|
||||
b.AddUInt8Array(et.Compose());
|
||||
|
||||
content = b.ToArray();
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
TypeTemplate.parse(DC data, [int offset = 0, int? contentLength]) {
|
||||
// cool Dart feature
|
||||
contentLength ??= data.length;
|
||||
@@ -494,6 +296,7 @@ class TypeTemplate {
|
||||
_content = data.clip(offset, contentLength);
|
||||
|
||||
var hasParent = (data.getUint8(offset) & 0x80) > 0;
|
||||
var hasClassAnnotation = (data.getUint8(offset) & 0x40) > 0;
|
||||
|
||||
_templateType = TemplateType.values[data.getUint8(offset++) & 0xF];
|
||||
|
||||
@@ -502,11 +305,22 @@ class TypeTemplate {
|
||||
_className = data.getString(offset + 1, data[offset]);
|
||||
offset += data[offset] + 1;
|
||||
|
||||
//print(" annotation : ${_className} ${hasAnnotation}");
|
||||
|
||||
if (hasParent) {
|
||||
_parentId = data.getGuid(offset);
|
||||
offset += 16;
|
||||
}
|
||||
|
||||
if (hasClassAnnotation) {
|
||||
var len = data.getUint16(offset);
|
||||
offset += 2;
|
||||
_annotation = data.getString(offset, len);
|
||||
offset += len;
|
||||
|
||||
//print("Has annotation ${_annotation}");
|
||||
}
|
||||
|
||||
_version = data.getInt32(offset);
|
||||
offset += 4;
|
||||
|
||||
@@ -524,8 +338,8 @@ class TypeTemplate {
|
||||
|
||||
if (type == 0) // function
|
||||
{
|
||||
String? expansion = null;
|
||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
||||
String? annotation = null;
|
||||
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||
|
||||
var name = data.getString(offset + 1, data[offset]);
|
||||
offset += data[offset] + 1;
|
||||
@@ -543,24 +357,24 @@ class TypeTemplate {
|
||||
offset += art.size;
|
||||
}
|
||||
|
||||
if (hasExpansion) // expansion ?
|
||||
if (hasAnnotation) // annotation ?
|
||||
{
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
expansion = data.getString(offset, cs);
|
||||
annotation = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var ft = new FunctionTemplate(this, functionIndex++, name, inherited,
|
||||
arguments, dt.type, expansion);
|
||||
arguments, dt.type, annotation);
|
||||
|
||||
_functions.add(ft);
|
||||
} else if (type == 1) // property
|
||||
{
|
||||
String? readExpansion = null, writeExpansion = null;
|
||||
String? readAnnotation = null, writeAnnotation = null;
|
||||
|
||||
var hasReadExpansion = ((data[offset] & 0x8) == 0x8);
|
||||
var hasWriteExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
var hasReadAnnotation = ((data[offset] & 0x8) == 0x8);
|
||||
var hasWriteAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||
var recordable = ((data[offset] & 1) == 1);
|
||||
var permission = (data[offset++] >> 1) & 0x3;
|
||||
var name = data.getString(offset + 1, data[offset]);
|
||||
@@ -571,30 +385,30 @@ class TypeTemplate {
|
||||
|
||||
offset += dt.size;
|
||||
|
||||
if (hasReadExpansion) // expansion ?
|
||||
if (hasReadAnnotation) // annotation ?
|
||||
{
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
readExpansion = data.getString(offset, cs);
|
||||
readAnnotation = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
if (hasWriteExpansion) // expansion ?
|
||||
if (hasWriteAnnotation) // annotation ?
|
||||
{
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
writeExpansion = data.getString(offset, cs);
|
||||
writeAnnotation = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var pt = new PropertyTemplate(this, propertyIndex++, name, inherited,
|
||||
dt.type, readExpansion, writeExpansion, recordable);
|
||||
dt.type, readAnnotation, writeAnnotation, recordable);
|
||||
|
||||
_properties.add(pt);
|
||||
} else if (type == 2) // Event
|
||||
{
|
||||
String? expansion = null;
|
||||
var hasExpansion = ((data[offset] & 0x10) == 0x10);
|
||||
String? annotation = null;
|
||||
var hasAnnotation = ((data[offset] & 0x10) == 0x10);
|
||||
var listenable = ((data[offset++] & 0x8) == 0x8);
|
||||
|
||||
var name = data.getString(offset + 1, data[offset]);
|
||||
@@ -604,21 +418,21 @@ class TypeTemplate {
|
||||
|
||||
offset += dt.size;
|
||||
|
||||
if (hasExpansion) // expansion ?
|
||||
if (hasAnnotation) // annotation ?
|
||||
{
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
expansion = data.getString(offset, cs);
|
||||
annotation = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var et = new EventTemplate(this, eventIndex++, name, inherited, dt.type,
|
||||
expansion, listenable);
|
||||
annotation, listenable);
|
||||
|
||||
_events.add(et);
|
||||
} else if (type == 3) {
|
||||
String? expansion = null;
|
||||
var hasExpansion = ((data[offset++] & 0x10) == 0x10);
|
||||
String? annotation = null;
|
||||
var hasAnnotation = ((data[offset++] & 0x10) == 0x10);
|
||||
|
||||
var name = data.getString(offset + 1, data[offset]);
|
||||
offset += data[offset] + 1;
|
||||
@@ -631,16 +445,16 @@ class TypeTemplate {
|
||||
|
||||
offset += parsed.size;
|
||||
|
||||
if (hasExpansion) // expansion ?
|
||||
if (hasAnnotation) // annotation ?
|
||||
{
|
||||
var cs = data.getUint32(offset);
|
||||
offset += 4;
|
||||
expansion = data.getString(offset, cs);
|
||||
annotation = data.getString(offset, cs);
|
||||
offset += cs;
|
||||
}
|
||||
|
||||
var ct = new ConstantTemplate(this, constantIndex++, name, inherited,
|
||||
dt.type, parsed.reply.result, expansion);
|
||||
dt.type, parsed.reply.result, annotation);
|
||||
|
||||
_constants.add(ct);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user