2
0
mirror of https://github.com/esiur/esiur-dart.git synced 2026-04-02 09:38:20 +00:00
This commit is contained in:
2021-07-21 12:18:01 +03:00
parent 737397da11
commit 6be04c39ed
27 changed files with 659 additions and 513 deletions

View File

@@ -29,6 +29,6 @@ class MemberTemplate
DC compose()
{
// return DC.ToBytes(Name);
return DC.stringToBytes(_name);
}
}

View File

@@ -10,7 +10,7 @@ import '../StorageMode.dart';
class PropertyTemplate extends MemberTemplate {
TemplateDataType valueType;
int permission;
int permission = 0;
int storage;

View File

@@ -26,7 +26,7 @@ class TemplateDataType {
TemplateDataType.fromType(type, bool isArray) {
int dt;
if (type == null)
if (type == null || type == dynamic)
dt = DataType.Void;
else if (type is int) {
dt = type;
@@ -50,7 +50,7 @@ class TemplateDataType {
dt = DataType.Int64;
else if (type == Float)
dt = DataType.Float32;
else if (type == Double)
else if (type == Double || type == double)
dt = DataType.Float64;
else if (type == String)
dt = DataType.String;

View File

@@ -5,9 +5,10 @@ class TemplateDescriber {
final List<Evt> events;
final List<Func> functions;
final String nameSpace;
final int version;
TemplateDescriber(this.nameSpace,
{this.properties, this.functions, this.events});
{this.properties, this.functions, this.events, this.version = 0});
}
// class Property<T> {
@@ -48,7 +49,8 @@ class Prop {
final bool isArray;
final String readAnnotation;
final String writeAnnotation;
Prop(this.name, this.type, this.isArray, [this.readAnnotation = null, this.writeAnnotation = null]);
Prop(this.name, this.type, this.isArray,
[this.readAnnotation = null, this.writeAnnotation = null]);
}
class Evt {
@@ -58,7 +60,8 @@ class Evt {
final bool isArray;
final String annotation;
Evt(this.name, this.type, this.isArray, [this.listenable = false, this.annotation]);
Evt(this.name, this.type, this.isArray,
[this.listenable = false, this.annotation]);
}
class Func {
@@ -68,7 +71,7 @@ class Func {
final bool isArray;
final String annotation;
Func(this.name, this.returnType, this.argsType, this.isArray,
Func(this.name, this.returnType, this.isArray, this.argsType,
[this.annotation = null]);
}

View File

@@ -1,5 +1,7 @@
import 'dart:ffi';
import '../../Net/IIP/DistributedResource.dart';
import '../../Data/BinaryList.dart';
import '../../Security/Integrity/SHA256.dart';
@@ -55,8 +57,7 @@ class TypeTemplate {
*/
//@TODO: implement
static List<TypeTemplate> getDependencies(TypeTemplate template) =>
[];
static List<TypeTemplate> getDependencies(TypeTemplate template) => [];
EventTemplate getEventTemplateByName(String eventName) {
for (var i in _events) if (i.name == eventName) return i;
@@ -106,15 +107,27 @@ class TypeTemplate {
List<PropertyTemplate> get properties => _properties;
TypeTemplate.fromType(Type type, [bool addToWarehouse, bool isWrapper]) {
TypeTemplate.fromType(Type type, [bool addToWarehouse = false]) {
// debugging print("FromType ${type.toString()}");
var instance = Warehouse.createInstance(type);
if (instance is IRecord)
_templateType = TemplateType.Record;
if (instance is DistributedResource)
_templateType = TemplateType.Wrapper;
else if (instance is IResource)
_templateType = TemplateType.Resource;
else if (instance is IRecord)
_templateType = TemplateType.Record;
else
throw new Exception("Type is neither a resource nor a record.");
throw new Exception(
"Type must implement IResource, IRecord or inherit from DistributedResource.");
// if (instance is IRecord)
// _templateType = TemplateType.Record;
// else if (instance is IResource)
// _templateType = TemplateType.Resource;
// else
// throw new Exception("Type is neither a resource nor a record.");
TemplateDescriber describer = instance.template;
@@ -125,47 +138,59 @@ class TypeTemplate {
// set guid
_classId = getTypeGuid(_className);
_version = describer.version;
if (addToWarehouse) Warehouse.putTemplate(this);
// _templates.add(template.classId, template);
for (var i = 0; i < describer.properties.length; i++) {
var pi = describer.properties[i];
var pt = PropertyTemplate(
this,
i,
pi.name,
TemplateDataType.fromType(pi.type, pi.isArray),
pi.readAnnotation,
pi.writeAnnotation,
0);
properties.add(pt);
}
if (describer.properties != null)
for (var i = 0; i < describer.properties.length; i++) {
var pi = describer.properties[i];
var pt = PropertyTemplate(
this,
i,
pi.name,
TemplateDataType.fromType(pi.type, pi.isArray),
pi.readAnnotation,
pi.writeAnnotation,
0);
properties.add(pt);
}
for (var i = 0; i < describer.functions.length; i++) {
var fi = describer.functions[i];
if (describer.functions != null)
for (var i = 0; i < describer.functions.length; i++) {
var fi = describer.functions[i];
List<ArgumentTemplate> args = fi.argsType.map((arg) => ArgumentTemplate(
arg.name, TemplateDataType.fromType(arg.type, arg.isArray)));
List<ArgumentTemplate> args = fi.argsType
.map((arg) => ArgumentTemplate(
arg.name, TemplateDataType.fromType(arg.type, arg.isArray)))
.toList();
var ft = FunctionTemplate(this, i, fi.name, args,
TemplateDataType.fromType(fi.returnType, fi.isArray), fi.annotation);
var ft = FunctionTemplate(
this,
i,
fi.name,
args,
TemplateDataType.fromType(fi.returnType, fi.isArray),
fi.annotation);
functions.add(ft);
}
functions.add(ft);
}
for (var i = 0; i < describer.events.length; i++) {
var ei = describer.events[i];
if (describer.events != null)
for (var i = 0; i < describer.events.length; i++) {
var ei = describer.events[i];
var et = new EventTemplate(
this,
i,
ei.name,
TemplateDataType.fromType(ei.type, ei.isArray),
ei.annotation,
ei.listenable);
var et = new EventTemplate(
this,
i,
ei.name,
TemplateDataType.fromType(ei.type, ei.isArray),
ei.annotation,
ei.listenable);
events.add(et);
}
events.add(et);
}
// append signals
events.forEach(_members.add);