forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
595
Kha/Tools/macos/std/haxe/rtti/CType.hx
Normal file
595
Kha/Tools/macos/std/haxe/rtti/CType.hx
Normal file
@ -0,0 +1,595 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.rtti;
|
||||
|
||||
/**
|
||||
The (dot-)path of the runtime type.
|
||||
**/
|
||||
typedef Path = String;
|
||||
|
||||
/**
|
||||
A list of strings representing the targets where the type is available.
|
||||
**/
|
||||
typedef Platforms = Array<String>;
|
||||
|
||||
/**
|
||||
The function argument runtime type information.
|
||||
**/
|
||||
typedef FunctionArgument = {name:String, opt:Bool, t:CType, ?value:String};
|
||||
|
||||
/**
|
||||
The runtime member types.
|
||||
**/
|
||||
enum CType {
|
||||
CUnknown;
|
||||
CEnum(name:Path, params:Array<CType>);
|
||||
CClass(name:Path, params:Array<CType>);
|
||||
CTypedef(name:Path, params:Array<CType>);
|
||||
CFunction(args:Array<FunctionArgument>, ret:CType);
|
||||
CAnonymous(fields:Array<ClassField>);
|
||||
CDynamic(?t:CType);
|
||||
CAbstract(name:Path, params:Array<CType>);
|
||||
}
|
||||
|
||||
/**
|
||||
The type parameters in the runtime type information.
|
||||
**/
|
||||
typedef PathParams = {
|
||||
/**
|
||||
The path of the type.
|
||||
**/
|
||||
var path:Path;
|
||||
|
||||
/**
|
||||
The array of parameters types.
|
||||
**/
|
||||
var params:Array<CType>;
|
||||
};
|
||||
|
||||
/**
|
||||
An array of strings representing the names of the type parameters the type
|
||||
has. As of Haxe 3.2.0, this does not include the constraints.
|
||||
**/
|
||||
typedef TypeParams = Array<String>; // no constraints
|
||||
|
||||
/**
|
||||
Represents the runtime rights of a type.
|
||||
**/
|
||||
enum Rights {
|
||||
RNormal;
|
||||
RNo;
|
||||
RCall(m:String);
|
||||
RMethod;
|
||||
RDynamic;
|
||||
RInline;
|
||||
}
|
||||
|
||||
/**
|
||||
The list of runtime metadata.
|
||||
**/
|
||||
typedef MetaData = Array<{name:String, params:Array<String>}>;
|
||||
|
||||
/**
|
||||
The runtime class field information.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti-structure.html#class-field-information>
|
||||
**/
|
||||
typedef ClassField = {
|
||||
/**
|
||||
The name of the field.
|
||||
**/
|
||||
var name:String;
|
||||
|
||||
/**
|
||||
The type of the field.
|
||||
**/
|
||||
var type:CType;
|
||||
|
||||
/**
|
||||
Whether or not the field is `public`.
|
||||
**/
|
||||
var isPublic:Bool;
|
||||
|
||||
/**
|
||||
Whether or not the field is `final`.
|
||||
**/
|
||||
var isFinal:Bool;
|
||||
|
||||
/**
|
||||
Whether or not the field overrides another field.
|
||||
**/
|
||||
var isOverride:Bool;
|
||||
|
||||
/**
|
||||
The documentation of the field. This information is only available
|
||||
if the compiler flag `-D use_rtti_doc` was in place. Otherwise, or
|
||||
if the field has no documentation, the value is `null`.
|
||||
**/
|
||||
var doc:Null<String>;
|
||||
|
||||
/**
|
||||
The [read access](https://haxe.org/manual/class-field-property.html#define-read-access)
|
||||
behavior of the field.
|
||||
**/
|
||||
var get:Rights;
|
||||
|
||||
/**
|
||||
The [write access](https://haxe.org/manual/class-field-property.html#define-write-access)
|
||||
behavior of the field.
|
||||
**/
|
||||
var set:Rights;
|
||||
|
||||
/**
|
||||
An array of strings representing the names of the type parameters
|
||||
the field has.
|
||||
**/
|
||||
var params:TypeParams;
|
||||
|
||||
/**
|
||||
A list of strings representing the targets where the field is available.
|
||||
**/
|
||||
var platforms:Platforms;
|
||||
|
||||
/**
|
||||
The meta data the field was annotated with.
|
||||
**/
|
||||
var meta:MetaData;
|
||||
|
||||
/**
|
||||
The line number where the field is defined. This information is only
|
||||
available if the field has an expression.
|
||||
Otherwise the value is `null`.
|
||||
**/
|
||||
var line:Null<Int>;
|
||||
|
||||
/**
|
||||
The list of available overloads for the fields or `null` if no overloads
|
||||
exists.
|
||||
**/
|
||||
var overloads:Null<Array<ClassField>>;
|
||||
|
||||
/**
|
||||
The actual expression of the field or `null` if there is no expression.
|
||||
**/
|
||||
var expr:Null<String>;
|
||||
};
|
||||
|
||||
/**
|
||||
The general runtime type information.
|
||||
**/
|
||||
typedef TypeInfos = {
|
||||
/**
|
||||
The type path of the type.
|
||||
**/
|
||||
var path:Path;
|
||||
|
||||
/**
|
||||
The type path of the module containing the type.
|
||||
**/
|
||||
var module:Path;
|
||||
|
||||
/**
|
||||
The full slash path of the .hx file containing the type.
|
||||
This might be `null` in case there is no such file, e.g. if the
|
||||
type is defined through a macro.
|
||||
**/
|
||||
var file:Null<String>;
|
||||
|
||||
/**
|
||||
An array of strings representing the names of the type parameters the
|
||||
type has.
|
||||
**/
|
||||
var params:TypeParams;
|
||||
|
||||
/**
|
||||
The documentation of the type. This information is only available
|
||||
if the compiler flag `-D use_rtti_doc` was in place. Otherwise, or if
|
||||
the constructor has no documentation, the value is `null`.
|
||||
**/
|
||||
var doc:Null<String>;
|
||||
|
||||
/**
|
||||
Whether or not the type is [`private`](https://haxe.org/manual/type-system-module-sub-types.html#define-private-type).
|
||||
**/
|
||||
var isPrivate:Bool;
|
||||
|
||||
/**
|
||||
A list of strings representing the targets where the type is available.
|
||||
**/
|
||||
var platforms:Platforms;
|
||||
|
||||
/**
|
||||
The [metadata](https://haxe.org/manual/lf-metadata.html) the type was
|
||||
annotated with.
|
||||
**/
|
||||
var meta:MetaData;
|
||||
};
|
||||
|
||||
/**
|
||||
The runtime class definition information.
|
||||
**/
|
||||
typedef Classdef = TypeInfos & {
|
||||
/**
|
||||
Whether or not the class is [extern](https://haxe.org/manual/lf-externs.html).
|
||||
**/
|
||||
var isExtern:Bool;
|
||||
|
||||
/**
|
||||
Whether or not the class is `final`.
|
||||
**/
|
||||
var isFinal:Bool;
|
||||
|
||||
/**
|
||||
Whether or not the class is actually an [interface](https://haxe.org/manual/types-interfaces.html).
|
||||
**/
|
||||
var isInterface:Bool;
|
||||
|
||||
/**
|
||||
The class' parent class defined by its type path and list of type
|
||||
parameters.
|
||||
**/
|
||||
var superClass:Null<PathParams>;
|
||||
|
||||
/**
|
||||
The list of interfaces defined by their type path and list of type
|
||||
parameters.
|
||||
**/
|
||||
var interfaces:Array<PathParams>;
|
||||
|
||||
/**
|
||||
The list of member [class fields](https://haxe.org/manual/class-field.html).
|
||||
**/
|
||||
var fields:Array<ClassField>;
|
||||
|
||||
/**
|
||||
The list of static class fields.
|
||||
**/
|
||||
var statics:Array<ClassField>;
|
||||
|
||||
/**
|
||||
The type which is dynamically implemented by the class or `null` if no
|
||||
such type exists.
|
||||
**/
|
||||
var tdynamic:Null<CType>;
|
||||
};
|
||||
|
||||
/**
|
||||
The runtime enum constructor information.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti-structure.html#enum-constructor-information>
|
||||
**/
|
||||
typedef EnumField = {
|
||||
/**
|
||||
The name of the constructor.
|
||||
**/
|
||||
var name:String;
|
||||
|
||||
/**
|
||||
The list of arguments the constructor has or `null` if no arguments are
|
||||
available.
|
||||
**/
|
||||
var args:Null<Array<{name:String, opt:Bool, t:CType}>>;
|
||||
|
||||
/**
|
||||
The documentation of the constructor. This information is only available
|
||||
if the compiler flag `-D use_rtti_doc` was in place. Otherwise, or if
|
||||
the constructor has no documentation, the value is `null`.
|
||||
**/
|
||||
var doc:String;
|
||||
|
||||
/**
|
||||
A list of strings representing the targets where the constructor is
|
||||
available.
|
||||
**/
|
||||
var platforms:Platforms;
|
||||
|
||||
/**
|
||||
The meta data the constructor was annotated with.
|
||||
**/
|
||||
var meta:MetaData;
|
||||
};
|
||||
|
||||
/**
|
||||
The enum runtime type information.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti-structure.html#enum-type-information>
|
||||
**/
|
||||
typedef Enumdef = TypeInfos & {
|
||||
/**
|
||||
Whether or not the enum is [extern](https://haxe.org/manual/lf-externs.html).
|
||||
**/
|
||||
var isExtern:Bool;
|
||||
|
||||
/**
|
||||
The list of enum constructors.
|
||||
**/
|
||||
var constructors:Array<EnumField>;
|
||||
};
|
||||
|
||||
/**
|
||||
The typedef runtime information.
|
||||
**/
|
||||
typedef Typedef = TypeInfos & {
|
||||
/**
|
||||
The type of the typedef.
|
||||
**/
|
||||
var type:CType;
|
||||
|
||||
/**
|
||||
The types of the typedef, by platform.
|
||||
**/
|
||||
var types:Map<String, CType>; // by platform
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
The abstract type runtime information.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti-structure.html#abstract-type-information>
|
||||
**/
|
||||
typedef Abstractdef = TypeInfos & {
|
||||
var to:Array<{t:CType, field:Null<String>}>;
|
||||
var from:Array<{t:CType, field:Null<String>}>;
|
||||
var impl:Classdef;
|
||||
var athis:CType;
|
||||
};
|
||||
|
||||
/**
|
||||
The tree types of the runtime type.
|
||||
**/
|
||||
enum TypeTree {
|
||||
TPackage(name:String, full:String, subs:Array<TypeTree>);
|
||||
TClassdecl(c:Classdef);
|
||||
TEnumdecl(e:Enumdef);
|
||||
TTypedecl(t:Typedef);
|
||||
TAbstractdecl(a:Abstractdef);
|
||||
}
|
||||
|
||||
/**
|
||||
Array of `TypeTree`.
|
||||
**/
|
||||
typedef TypeRoot = Array<TypeTree>;
|
||||
|
||||
/**
|
||||
Contains type and equality checks functionalities for RTTI.
|
||||
**/
|
||||
class TypeApi {
|
||||
public static function typeInfos(t:TypeTree):TypeInfos {
|
||||
var inf:TypeInfos;
|
||||
switch (t) {
|
||||
case TClassdecl(c):
|
||||
inf = c;
|
||||
case TEnumdecl(e):
|
||||
inf = e;
|
||||
case TTypedecl(t):
|
||||
inf = t;
|
||||
case TAbstractdecl(a):
|
||||
inf = a;
|
||||
case TPackage(_, _, _):
|
||||
throw "Unexpected Package";
|
||||
}
|
||||
return inf;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns `true` if the given `CType` is a variable or `false` if it is a
|
||||
function.
|
||||
**/
|
||||
public static function isVar(t:CType) {
|
||||
return switch (t) {
|
||||
case CFunction(_, _): false;
|
||||
default: true;
|
||||
}
|
||||
}
|
||||
|
||||
static function leq<T>(f:T->T->Bool, l1:Array<T>, l2:Array<T>) {
|
||||
var it = l2.iterator();
|
||||
for (e1 in l1) {
|
||||
if (!it.hasNext())
|
||||
return false;
|
||||
var e2 = it.next();
|
||||
if (!f(e1, e2))
|
||||
return false;
|
||||
}
|
||||
if (it.hasNext())
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Unlike `r1 == r2`, this function performs a deep equality check on
|
||||
the given `Rights` instances.
|
||||
|
||||
If `r1` or `r2` are `null`, the result is unspecified.
|
||||
**/
|
||||
public static function rightsEq(r1:Rights, r2:Rights) {
|
||||
if (r1 == r2)
|
||||
return true;
|
||||
switch (r1) {
|
||||
case RCall(m1):
|
||||
switch (r2) {
|
||||
case RCall(m2):
|
||||
return m1 == m2;
|
||||
default:
|
||||
}
|
||||
default:
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Unlike `t1 == t2`, this function performs a deep equality check on
|
||||
the given `CType` instances.
|
||||
|
||||
If `t1` or `t2` are `null`, the result is unspecified.
|
||||
**/
|
||||
public static function typeEq(t1:CType, t2:CType) {
|
||||
switch (t1) {
|
||||
case CUnknown:
|
||||
return t2 == CUnknown;
|
||||
case CEnum(name, params):
|
||||
switch (t2) {
|
||||
case CEnum(name2, params2):
|
||||
return name == name2 && leq(typeEq, params, params2);
|
||||
default:
|
||||
}
|
||||
case CClass(name, params):
|
||||
switch (t2) {
|
||||
case CClass(name2, params2):
|
||||
return name == name2 && leq(typeEq, params, params2);
|
||||
default:
|
||||
}
|
||||
case CAbstract(name, params):
|
||||
switch (t2) {
|
||||
case CAbstract(name2, params2):
|
||||
return name == name2 && leq(typeEq, params, params2);
|
||||
default:
|
||||
}
|
||||
case CTypedef(name, params):
|
||||
switch (t2) {
|
||||
case CTypedef(name2, params2):
|
||||
return name == name2 && leq(typeEq, params, params2);
|
||||
default:
|
||||
}
|
||||
case CFunction(args, ret):
|
||||
switch (t2) {
|
||||
case CFunction(args2, ret2):
|
||||
return leq(function(a:FunctionArgument, b:FunctionArgument) {
|
||||
return a.name == b.name && a.opt == b.opt && typeEq(a.t, b.t);
|
||||
}, args, args2) && typeEq(ret, ret2);
|
||||
default:
|
||||
}
|
||||
case CAnonymous(fields):
|
||||
switch (t2) {
|
||||
case CAnonymous(fields2):
|
||||
return leq(function(a, b) return fieldEq(a, b), fields, fields2);
|
||||
default:
|
||||
}
|
||||
case CDynamic(t):
|
||||
switch (t2) {
|
||||
case CDynamic(t2):
|
||||
if ((t == null) != (t2 == null))
|
||||
return false;
|
||||
return t == null || typeEq(t, t2);
|
||||
default:
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
Unlike `f1 == f2`, this function performs a deep equality check on
|
||||
the given `ClassField` instances.
|
||||
|
||||
If `f1` or `f2` are `null`, the result is unspecified.
|
||||
**/
|
||||
public static function fieldEq(f1:ClassField, f2:ClassField) {
|
||||
if (f1.name != f2.name)
|
||||
return false;
|
||||
if (!typeEq(f1.type, f2.type))
|
||||
return false;
|
||||
if (f1.isPublic != f2.isPublic)
|
||||
return false;
|
||||
if (f1.doc != f2.doc)
|
||||
return false;
|
||||
if (!rightsEq(f1.get, f2.get))
|
||||
return false;
|
||||
if (!rightsEq(f1.set, f2.set))
|
||||
return false;
|
||||
if ((f1.params == null) != (f2.params == null))
|
||||
return false;
|
||||
if (f1.params != null && f1.params.join(":") != f2.params.join(":"))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
Unlike `c1 == c2`, this function performs a deep equality check on
|
||||
the arguments of the enum constructors, if exists.
|
||||
|
||||
If `c1` or `c2` are `null`, the result is unspecified.
|
||||
**/
|
||||
public static function constructorEq(c1:EnumField, c2:EnumField) {
|
||||
if (c1.name != c2.name)
|
||||
return false;
|
||||
if (c1.doc != c2.doc)
|
||||
return false;
|
||||
if ((c1.args == null) != (c2.args == null))
|
||||
return false;
|
||||
if (c1.args != null && !leq(function(a, b) {
|
||||
return a.name == b.name && a.opt == b.opt && typeEq(a.t, b.t);
|
||||
}, c1.args, c2.args))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
The `CTypeTools` class contains some extra functionalities for handling
|
||||
`CType` instances.
|
||||
**/
|
||||
class CTypeTools {
|
||||
/**
|
||||
Get the string representation of `CType`.
|
||||
**/
|
||||
static public function toString(t:CType):String {
|
||||
return switch (t) {
|
||||
case CUnknown:
|
||||
"unknown";
|
||||
case CClass(name, params), CEnum(name, params), CTypedef(name, params), CAbstract(name, params):
|
||||
nameWithParams(name, params);
|
||||
case CFunction(args, ret):
|
||||
if (args.length == 0) {
|
||||
"Void -> " + toString(ret);
|
||||
} else {
|
||||
args.map(functionArgumentName).join(" -> ") + " -> " + toString(ret);
|
||||
}
|
||||
case CDynamic(d):
|
||||
if (d == null) {
|
||||
"Dynamic";
|
||||
} else {
|
||||
"Dynamic<" + toString(d) + ">";
|
||||
}
|
||||
case CAnonymous(fields):
|
||||
"{ " + fields.map(classField).join(", ") + "}";
|
||||
}
|
||||
}
|
||||
|
||||
static function nameWithParams(name:String, params:Array<CType>) {
|
||||
if (params.length == 0) {
|
||||
return name;
|
||||
}
|
||||
return name + "<" + params.map(toString).join(", ") + ">";
|
||||
}
|
||||
|
||||
static function functionArgumentName(arg:FunctionArgument) {
|
||||
return (arg.opt ? "?" : "")
|
||||
+ (arg.name == "" ? "" : arg.name + ":")
|
||||
+ toString(arg.t)
|
||||
+ (arg.value == null ? "" : " = " + arg.value);
|
||||
}
|
||||
|
||||
static function classField(cf:ClassField) {
|
||||
return cf.name + ":" + toString(cf.type);
|
||||
}
|
||||
}
|
93
Kha/Tools/macos/std/haxe/rtti/Meta.hx
Normal file
93
Kha/Tools/macos/std/haxe/rtti/Meta.hx
Normal file
@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.rtti;
|
||||
|
||||
private typedef MetaObject = {
|
||||
?fields:Dynamic<Dynamic<Null<Array<Dynamic>>>>,
|
||||
?statics:Dynamic<Dynamic<Null<Array<Dynamic>>>>,
|
||||
?obj:Dynamic<Null<Array<Dynamic>>>
|
||||
};
|
||||
|
||||
/**
|
||||
An API to access classes and enums metadata at runtime.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti.html>
|
||||
**/
|
||||
class Meta {
|
||||
/**
|
||||
Returns the metadata that were declared for the given type (class or enum)
|
||||
**/
|
||||
public static function getType(t:Dynamic):Dynamic<Array<Dynamic>> {
|
||||
var meta = getMeta(t);
|
||||
return (meta == null || meta.obj == null) ? {} : meta.obj;
|
||||
}
|
||||
|
||||
// Could move this to Type.hx?
|
||||
private static function isInterface(t:Dynamic):Bool {
|
||||
#if java
|
||||
return java.Lib.toNativeType(t).isInterface();
|
||||
#elseif cs
|
||||
return cs.Lib.toNativeType(t).IsInterface;
|
||||
#else
|
||||
throw "Something went wrong";
|
||||
#end
|
||||
}
|
||||
|
||||
private static function getMeta(t:Dynamic):MetaObject {
|
||||
#if php
|
||||
return php.Boot.getMeta(t.phpClassName);
|
||||
#elseif (java || cs)
|
||||
var ret = Reflect.field(t, "__meta__");
|
||||
if (ret == null && Std.isOfType(t, Class)) {
|
||||
if (isInterface(t)) {
|
||||
var name = Type.getClassName(t),
|
||||
cls = Type.resolveClass(name + '_HxMeta');
|
||||
if (cls != null)
|
||||
return Reflect.field(cls, "__meta__");
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
#elseif hl
|
||||
var t:hl.BaseType = t;
|
||||
return t.__meta__;
|
||||
#else
|
||||
return untyped t.__meta__;
|
||||
#end
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the metadata that were declared for the given class static fields
|
||||
**/
|
||||
public static function getStatics(t:Dynamic):Dynamic<Dynamic<Array<Dynamic>>> {
|
||||
var meta = getMeta(t);
|
||||
return (meta == null || meta.statics == null) ? {} : meta.statics;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns the metadata that were declared for the given class fields or enum constructors
|
||||
**/
|
||||
public static function getFields(t:Dynamic):Dynamic<Dynamic<Array<Dynamic>>> {
|
||||
var meta = getMeta(t);
|
||||
return (meta == null || meta.fields == null) ? {} : meta.fields;
|
||||
}
|
||||
}
|
64
Kha/Tools/macos/std/haxe/rtti/Rtti.hx
Normal file
64
Kha/Tools/macos/std/haxe/rtti/Rtti.hx
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.rtti;
|
||||
|
||||
import haxe.rtti.CType;
|
||||
|
||||
/**
|
||||
Rtti is a helper class which supplements the `@:rtti` metadata.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti.html>
|
||||
**/
|
||||
class Rtti {
|
||||
/**
|
||||
Returns the `haxe.rtti.CType.Classdef` corresponding to class `c`.
|
||||
|
||||
If `c` has no runtime type information, e.g. because no `@:rtti` was
|
||||
added, an exception of type `String` is thrown.
|
||||
|
||||
If `c` is `null`, the result is unspecified.
|
||||
**/
|
||||
static public function getRtti<T>(c:Class<T>):Classdef {
|
||||
var rtti = Reflect.field(c, "__rtti");
|
||||
if (rtti == null) {
|
||||
throw 'Class ${Type.getClassName(c)} has no RTTI information, consider adding @:rtti';
|
||||
}
|
||||
var x = Xml.parse(rtti).firstElement();
|
||||
var infos = new haxe.rtti.XmlParser().processElement(x);
|
||||
switch (infos) {
|
||||
case TClassdecl(c):
|
||||
return c;
|
||||
case var t:
|
||||
throw 'Enum mismatch: expected TClassDecl but found $t';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Tells if `c` has runtime type information.
|
||||
|
||||
If `c` is `null`, the result is unspecified.
|
||||
**/
|
||||
static public function hasRtti<T>(c:Class<T>):Bool {
|
||||
return Lambda.has(Type.getClassFields(c), "__rtti");
|
||||
}
|
||||
}
|
637
Kha/Tools/macos/std/haxe/rtti/XmlParser.hx
Normal file
637
Kha/Tools/macos/std/haxe/rtti/XmlParser.hx
Normal file
@ -0,0 +1,637 @@
|
||||
/*
|
||||
* Copyright (C)2005-2019 Haxe Foundation
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package haxe.rtti;
|
||||
|
||||
import haxe.rtti.CType;
|
||||
import haxe.xml.Access;
|
||||
|
||||
/**
|
||||
XmlParser processes the runtime type information (RTTI) which
|
||||
is stored as a XML string in a static field `__rtti`.
|
||||
|
||||
@see <https://haxe.org/manual/cr-rtti.html>
|
||||
**/
|
||||
class XmlParser {
|
||||
public var root:TypeRoot;
|
||||
|
||||
var curplatform:String;
|
||||
|
||||
public function new() {
|
||||
root = new Array();
|
||||
}
|
||||
|
||||
public function sort(?l:TypeRoot) {
|
||||
if (l == null)
|
||||
l = root;
|
||||
l.sort(function(e1, e2) {
|
||||
var n1 = switch e1 {
|
||||
case TPackage(p, _, _): " " + p;
|
||||
default: TypeApi.typeInfos(e1).path;
|
||||
};
|
||||
var n2 = switch e2 {
|
||||
case TPackage(p, _, _): " " + p;
|
||||
default: TypeApi.typeInfos(e2).path;
|
||||
};
|
||||
if (n1 > n2)
|
||||
return 1;
|
||||
return -1;
|
||||
});
|
||||
for (x in l)
|
||||
switch (x) {
|
||||
case TPackage(_, _, l):
|
||||
sort(l);
|
||||
case TClassdecl(c):
|
||||
sortFields(c.fields);
|
||||
sortFields(c.statics);
|
||||
case TEnumdecl(_):
|
||||
case TAbstractdecl(_):
|
||||
case TTypedecl(_):
|
||||
}
|
||||
}
|
||||
|
||||
function sortFields(a:Array<ClassField>) {
|
||||
a.sort(function(f1:ClassField, f2:ClassField) {
|
||||
var v1 = TypeApi.isVar(f1.type);
|
||||
var v2 = TypeApi.isVar(f2.type);
|
||||
if (v1 && !v2)
|
||||
return -1;
|
||||
if (v2 && !v1)
|
||||
return 1;
|
||||
if (f1.name == "new")
|
||||
return -1;
|
||||
if (f2.name == "new")
|
||||
return 1;
|
||||
if (f1.name > f2.name)
|
||||
return 1;
|
||||
return -1;
|
||||
});
|
||||
}
|
||||
|
||||
public function process(x:Xml, platform:String) {
|
||||
curplatform = platform;
|
||||
xroot(new Access(x));
|
||||
}
|
||||
|
||||
// merge inline and not inline
|
||||
function mergeRights(f1:ClassField, f2:ClassField) {
|
||||
if (f1.get == RInline && f1.set == RNo && f2.get == RNormal && f2.set == RMethod) {
|
||||
f1.get = RNormal;
|
||||
f1.set = RMethod;
|
||||
return true;
|
||||
}
|
||||
return Type.enumEq(f1.get, f2.get) && Type.enumEq(f1.set, f2.set);
|
||||
}
|
||||
|
||||
function mergeDoc(f1:ClassField, f2:ClassField) {
|
||||
if (f1.doc == null)
|
||||
f1.doc = f2.doc;
|
||||
else if (f2.doc == null)
|
||||
f2.doc = f1.doc;
|
||||
return true;
|
||||
}
|
||||
|
||||
function mergeFields(f:ClassField, f2:ClassField) {
|
||||
return TypeApi.fieldEq(f, f2)
|
||||
|| (f.name == f2.name && (mergeRights(f, f2) || mergeRights(f2, f)) && mergeDoc(f, f2) && TypeApi.fieldEq(f, f2));
|
||||
}
|
||||
|
||||
public dynamic function newField(c:Classdef, f:ClassField) {}
|
||||
|
||||
function mergeClasses(c:Classdef, c2:Classdef) {
|
||||
// todo : compare supers & interfaces
|
||||
if (c.isInterface != c2.isInterface)
|
||||
return false;
|
||||
if (curplatform != null)
|
||||
c.platforms.push(curplatform);
|
||||
if (c.isExtern != c2.isExtern)
|
||||
c.isExtern = false;
|
||||
|
||||
for (f2 in c2.fields) {
|
||||
var found = null;
|
||||
for (f in c.fields)
|
||||
if (mergeFields(f, f2)) {
|
||||
found = f;
|
||||
break;
|
||||
}
|
||||
if (found == null) {
|
||||
newField(c, f2);
|
||||
c.fields.push(f2);
|
||||
} else if (curplatform != null)
|
||||
found.platforms.push(curplatform);
|
||||
}
|
||||
for (f2 in c2.statics) {
|
||||
var found = null;
|
||||
for (f in c.statics)
|
||||
if (mergeFields(f, f2)) {
|
||||
found = f;
|
||||
break;
|
||||
}
|
||||
if (found == null) {
|
||||
newField(c, f2);
|
||||
c.statics.push(f2);
|
||||
} else if (curplatform != null)
|
||||
found.platforms.push(curplatform);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function mergeEnums(e:Enumdef, e2:Enumdef) {
|
||||
if (e.isExtern != e2.isExtern)
|
||||
return false;
|
||||
if (curplatform != null)
|
||||
e.platforms.push(curplatform);
|
||||
for (c2 in e2.constructors) {
|
||||
var found = null;
|
||||
for (c in e.constructors)
|
||||
if (TypeApi.constructorEq(c, c2)) {
|
||||
found = c;
|
||||
break;
|
||||
}
|
||||
if (found == null)
|
||||
e.constructors.push(c2);
|
||||
else if (curplatform != null)
|
||||
found.platforms.push(curplatform);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function mergeTypedefs(t:Typedef, t2:Typedef) {
|
||||
if (curplatform == null)
|
||||
return false;
|
||||
t.platforms.push(curplatform);
|
||||
t.types.set(curplatform, t2.type);
|
||||
return true;
|
||||
}
|
||||
|
||||
function mergeAbstracts(a:Abstractdef, a2:Abstractdef) {
|
||||
if (curplatform == null)
|
||||
return false;
|
||||
if (a.to.length != a2.to.length || a.from.length != a2.from.length)
|
||||
return false;
|
||||
for (i in 0...a.to.length)
|
||||
if (!TypeApi.typeEq(a.to[i].t, a2.to[i].t))
|
||||
return false;
|
||||
for (i in 0...a.from.length)
|
||||
if (!TypeApi.typeEq(a.from[i].t, a2.from[i].t))
|
||||
return false;
|
||||
if (a2.impl != null)
|
||||
mergeClasses(a.impl, a2.impl);
|
||||
a.platforms.push(curplatform);
|
||||
return true;
|
||||
}
|
||||
|
||||
function merge(t:TypeTree) {
|
||||
var inf = TypeApi.typeInfos(t);
|
||||
var pack = inf.path.split(".");
|
||||
var cur = root;
|
||||
var curpack = new Array();
|
||||
pack.pop();
|
||||
for (p in pack) {
|
||||
var found = false;
|
||||
for (pk in cur)
|
||||
switch (pk) {
|
||||
case TPackage(pname, _, subs):
|
||||
if (pname == p) {
|
||||
found = true;
|
||||
cur = subs;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
}
|
||||
curpack.push(p);
|
||||
if (!found) {
|
||||
var pk = new Array();
|
||||
cur.push(TPackage(p, curpack.join("."), pk));
|
||||
cur = pk;
|
||||
}
|
||||
}
|
||||
for (ct in cur) {
|
||||
if (ct.match(TPackage(_)))
|
||||
continue;
|
||||
var tinf = TypeApi.typeInfos(ct);
|
||||
|
||||
// compare params ?
|
||||
if (tinf.path == inf.path) {
|
||||
var sameType = true;
|
||||
if ((tinf.doc == null) != (inf.doc == null)) {
|
||||
if (inf.doc == null)
|
||||
inf.doc = tinf.doc;
|
||||
else
|
||||
tinf.doc = inf.doc;
|
||||
}
|
||||
if (tinf.path == "haxe._Int64.NativeInt64")
|
||||
continue;
|
||||
if (tinf.module == inf.module && tinf.doc == inf.doc && tinf.isPrivate == inf.isPrivate)
|
||||
switch (ct) {
|
||||
case TClassdecl(c):
|
||||
switch (t) {
|
||||
case TClassdecl(c2):
|
||||
if (mergeClasses(c, c2))
|
||||
return;
|
||||
default:
|
||||
sameType = false;
|
||||
}
|
||||
case TEnumdecl(e):
|
||||
switch (t) {
|
||||
case TEnumdecl(e2):
|
||||
if (mergeEnums(e, e2))
|
||||
return;
|
||||
default:
|
||||
sameType = false;
|
||||
}
|
||||
case TTypedecl(td):
|
||||
switch (t) {
|
||||
case TTypedecl(td2):
|
||||
if (mergeTypedefs(td, td2))
|
||||
return;
|
||||
default:
|
||||
}
|
||||
case TAbstractdecl(a):
|
||||
switch (t) {
|
||||
case TAbstractdecl(a2):
|
||||
if (mergeAbstracts(a, a2))
|
||||
return;
|
||||
default:
|
||||
sameType = false;
|
||||
}
|
||||
case TPackage(_, _, _):
|
||||
sameType = false;
|
||||
}
|
||||
// we already have a mapping, but which is incompatible
|
||||
var msg = if (tinf.module != inf.module) "module " + inf.module + " should be " + tinf.module; else if (tinf.doc != inf.doc)
|
||||
"documentation is different";
|
||||
else if (tinf.isPrivate != inf.isPrivate)
|
||||
"private flag is different";
|
||||
else if (!sameType)
|
||||
"type kind is different";
|
||||
else
|
||||
"could not merge definition";
|
||||
throw "Incompatibilities between " + tinf.path + " in " + tinf.platforms.join(",") + " and " + curplatform + " (" + msg + ")";
|
||||
}
|
||||
}
|
||||
cur.push(t);
|
||||
}
|
||||
|
||||
function mkPath(p:String):Path {
|
||||
return p;
|
||||
}
|
||||
|
||||
function mkTypeParams(p:String):TypeParams {
|
||||
var pl = p.split(":");
|
||||
if (pl[0] == "")
|
||||
return new Array();
|
||||
return pl;
|
||||
}
|
||||
|
||||
function mkRights(r:String):Rights {
|
||||
return switch (r) {
|
||||
case "null": RNo;
|
||||
case "method": RMethod;
|
||||
case "dynamic": RDynamic;
|
||||
case "inline": RInline;
|
||||
default: RCall(r);
|
||||
}
|
||||
}
|
||||
|
||||
function xerror(c:Access):Dynamic {
|
||||
return throw "Invalid " + c.name;
|
||||
}
|
||||
|
||||
function xroot(x:Access) {
|
||||
for (c in x.x.elements())
|
||||
merge(processElement(c));
|
||||
}
|
||||
|
||||
public function processElement(x:Xml) {
|
||||
var c = new haxe.xml.Access(x);
|
||||
return switch (c.name) {
|
||||
case "class": TClassdecl(xclass(c));
|
||||
case "enum": TEnumdecl(xenum(c));
|
||||
case "typedef": TTypedecl(xtypedef(c));
|
||||
case "abstract": TAbstractdecl(xabstract(c));
|
||||
default: xerror(c);
|
||||
}
|
||||
}
|
||||
|
||||
function xmeta(x:Access):MetaData {
|
||||
var ml = [];
|
||||
for (m in x.nodes.m) {
|
||||
var pl = [];
|
||||
for (p in m.nodes.e)
|
||||
pl.push(p.innerHTML);
|
||||
ml.push({name: m.att.n, params: pl});
|
||||
}
|
||||
return ml;
|
||||
}
|
||||
|
||||
function xoverloads(x:Access):Array<ClassField> {
|
||||
var l = new Array();
|
||||
for (m in x.elements) {
|
||||
l.push(xclassfield(m));
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
function xpath(x:Access):PathParams {
|
||||
var path = mkPath(x.att.path);
|
||||
var params = new Array();
|
||||
for (c in x.elements)
|
||||
params.push(xtype(c));
|
||||
return {
|
||||
path: path,
|
||||
params: params,
|
||||
};
|
||||
}
|
||||
|
||||
function xclass(x:Access):Classdef {
|
||||
var csuper = null;
|
||||
var doc = null;
|
||||
var tdynamic = null;
|
||||
var interfaces = new Array();
|
||||
var fields = new Array();
|
||||
var statics = new Array();
|
||||
var meta = [];
|
||||
var isInterface = x.x.exists("interface");
|
||||
for (c in x.elements)
|
||||
switch (c.name) {
|
||||
case "haxe_doc":
|
||||
doc = c.innerData;
|
||||
case "extends":
|
||||
if (isInterface) {
|
||||
interfaces.push(xpath(c));
|
||||
} else {
|
||||
csuper = xpath(c);
|
||||
}
|
||||
case "implements":
|
||||
interfaces.push(xpath(c));
|
||||
case "haxe_dynamic":
|
||||
tdynamic = xtype(new Access(c.x.firstElement()));
|
||||
case "meta":
|
||||
meta = xmeta(c);
|
||||
default:
|
||||
if (c.x.exists("static"))
|
||||
statics.push(xclassfield(c));
|
||||
else
|
||||
fields.push(xclassfield(c));
|
||||
}
|
||||
return {
|
||||
file: if (x.has.file) x.att.file else null,
|
||||
path: mkPath(x.att.path),
|
||||
module: if (x.has.module) mkPath(x.att.module) else null,
|
||||
doc: doc,
|
||||
isPrivate: x.x.exists("private"),
|
||||
isExtern: x.x.exists("extern"),
|
||||
isFinal: x.x.exists("final"),
|
||||
isInterface: isInterface,
|
||||
params: mkTypeParams(x.att.params),
|
||||
superClass: csuper,
|
||||
interfaces: interfaces,
|
||||
fields: fields,
|
||||
statics: statics,
|
||||
tdynamic: tdynamic,
|
||||
platforms: defplat(),
|
||||
meta: meta,
|
||||
};
|
||||
}
|
||||
|
||||
function xclassfield(x:Access, ?defPublic = false):ClassField {
|
||||
var e = x.elements;
|
||||
var t = xtype(e.next());
|
||||
var doc = null;
|
||||
var meta = [];
|
||||
var overloads = null;
|
||||
for (c in e)
|
||||
switch (c.name) {
|
||||
case "haxe_doc":
|
||||
doc = c.innerData;
|
||||
case "meta":
|
||||
meta = xmeta(c);
|
||||
case "overloads":
|
||||
overloads = xoverloads(c);
|
||||
default:
|
||||
xerror(c);
|
||||
}
|
||||
return {
|
||||
name:x.name, type:t, isPublic:x.x.exists("public") || defPublic, isFinal:x.x.exists("final"), isOverride:x.x.exists("override"),
|
||||
line:if (x.has.line) Std.parseInt(x.att.line) else null, doc:doc, get:if (x.has.get) mkRights(x.att.get) else RNormal, set:if (x.has.set)
|
||||
mkRights(x.att.set)
|
||||
else
|
||||
RNormal, params:if (x.has.params) mkTypeParams(x.att.params) else [], platforms:defplat(), meta:meta, overloads:overloads, expr:if (x.has.expr)
|
||||
x.att.expr
|
||||
else
|
||||
null
|
||||
};
|
||||
}
|
||||
|
||||
function xenum(x:Access):Enumdef {
|
||||
var cl = new Array();
|
||||
var doc = null;
|
||||
var meta = [];
|
||||
for (c in x.elements)
|
||||
if (c.name == "haxe_doc")
|
||||
doc = c.innerData;
|
||||
else if (c.name == "meta")
|
||||
meta = xmeta(c);
|
||||
else
|
||||
cl.push(xenumfield(c));
|
||||
return {
|
||||
file: if (x.has.file) x.att.file else null,
|
||||
path: mkPath(x.att.path),
|
||||
module: if (x.has.module) mkPath(x.att.module) else null,
|
||||
doc: doc,
|
||||
isPrivate: x.x.exists("private"),
|
||||
isExtern: x.x.exists("extern"),
|
||||
params: mkTypeParams(x.att.params),
|
||||
constructors: cl,
|
||||
platforms: defplat(),
|
||||
meta: meta,
|
||||
};
|
||||
}
|
||||
|
||||
function xenumfield(x:Access):EnumField {
|
||||
var args = null;
|
||||
var docElements = x.x.elementsNamed("haxe_doc");
|
||||
var xdoc = if (docElements.hasNext()) docElements.next() else null;
|
||||
var meta = if (x.hasNode.meta) xmeta(x.node.meta) else [];
|
||||
if (x.has.a) {
|
||||
var names = x.att.a.split(":");
|
||||
var elts = x.elements;
|
||||
args = new Array();
|
||||
for (c in names) {
|
||||
var opt = false;
|
||||
if (c.charAt(0) == "?") {
|
||||
opt = true;
|
||||
c = c.substr(1);
|
||||
}
|
||||
args.push({
|
||||
name: c,
|
||||
opt: opt,
|
||||
t: xtype(elts.next()),
|
||||
});
|
||||
}
|
||||
}
|
||||
return {
|
||||
name: x.name,
|
||||
args: args,
|
||||
doc: if (xdoc == null) null else new Access(xdoc).innerData,
|
||||
meta: meta,
|
||||
platforms: defplat(),
|
||||
};
|
||||
}
|
||||
|
||||
function xabstract(x:Access):Abstractdef {
|
||||
var doc = null, impl = null, athis = null;
|
||||
var meta = [], to = [], from = [];
|
||||
for (c in x.elements)
|
||||
switch (c.name) {
|
||||
case "haxe_doc":
|
||||
doc = c.innerData;
|
||||
case "meta":
|
||||
meta = xmeta(c);
|
||||
case "to":
|
||||
for (t in c.elements)
|
||||
to.push({t: xtype(new Access(t.x.firstElement())), field: t.has.field ? t.att.field : null});
|
||||
case "from":
|
||||
for (t in c.elements)
|
||||
from.push({t: xtype(new Access(t.x.firstElement())), field: t.has.field ? t.att.field : null});
|
||||
case "impl":
|
||||
impl = xclass(c.node.resolve("class"));
|
||||
case "this":
|
||||
athis = xtype(new Access(c.x.firstElement()));
|
||||
default:
|
||||
xerror(c);
|
||||
}
|
||||
return {
|
||||
file: if (x.has.file) x.att.file else null,
|
||||
path: mkPath(x.att.path),
|
||||
module: if (x.has.module) mkPath(x.att.module) else null,
|
||||
doc: doc,
|
||||
isPrivate: x.x.exists("private"),
|
||||
params: mkTypeParams(x.att.params),
|
||||
platforms: defplat(),
|
||||
meta: meta,
|
||||
athis: athis,
|
||||
to: to,
|
||||
from: from,
|
||||
impl: impl
|
||||
};
|
||||
}
|
||||
|
||||
function xtypedef(x:Access):Typedef {
|
||||
var doc = null;
|
||||
var t = null;
|
||||
var meta = [];
|
||||
for (c in x.elements)
|
||||
if (c.name == "haxe_doc")
|
||||
doc = c.innerData;
|
||||
else if (c.name == "meta")
|
||||
meta = xmeta(c);
|
||||
else
|
||||
t = xtype(c);
|
||||
var types = new haxe.ds.StringMap();
|
||||
if (curplatform != null)
|
||||
types.set(curplatform, t);
|
||||
return {
|
||||
file: if (x.has.file) x.att.file else null,
|
||||
path: mkPath(x.att.path),
|
||||
module: if (x.has.module) mkPath(x.att.module) else null,
|
||||
doc: doc,
|
||||
isPrivate: x.x.exists("private"),
|
||||
params: mkTypeParams(x.att.params),
|
||||
type: t,
|
||||
types: types,
|
||||
platforms: defplat(),
|
||||
meta: meta,
|
||||
};
|
||||
}
|
||||
|
||||
function xtype(x:Access):CType {
|
||||
return switch (x.name) {
|
||||
case "unknown":
|
||||
CUnknown;
|
||||
case "e":
|
||||
CEnum(mkPath(x.att.path), xtypeparams(x));
|
||||
case "c":
|
||||
CClass(mkPath(x.att.path), xtypeparams(x));
|
||||
case "t":
|
||||
CTypedef(mkPath(x.att.path), xtypeparams(x));
|
||||
case "x":
|
||||
CAbstract(mkPath(x.att.path), xtypeparams(x));
|
||||
case "f":
|
||||
var args = new Array();
|
||||
var aname = x.att.a.split(":");
|
||||
var eargs = aname.iterator();
|
||||
var evalues = x.has.v ? x.att.v.split(":").iterator() : null;
|
||||
for (e in x.elements) {
|
||||
var opt = false;
|
||||
var a = eargs.hasNext() ? eargs.next() : null;
|
||||
if (a == null)
|
||||
a = "";
|
||||
if (a.charAt(0) == "?") {
|
||||
opt = true;
|
||||
a = a.substr(1);
|
||||
}
|
||||
var v = evalues == null || !evalues.hasNext() ? null : evalues.next();
|
||||
args.push({
|
||||
name: a,
|
||||
opt: opt,
|
||||
t: xtype(e),
|
||||
value: v == "" ? null : v
|
||||
});
|
||||
}
|
||||
var ret = args[args.length - 1];
|
||||
args.remove(ret);
|
||||
CFunction(args, ret.t);
|
||||
case "a":
|
||||
var fields = new Array();
|
||||
for (f in x.elements) {
|
||||
var f = xclassfield(f, true);
|
||||
f.platforms = new Array(); // platforms selection are on the type itself, not on fields
|
||||
fields.push(f);
|
||||
}
|
||||
CAnonymous(fields);
|
||||
case "d":
|
||||
var t = null;
|
||||
var tx = x.x.firstElement();
|
||||
if (tx != null)
|
||||
t = xtype(new Access(tx));
|
||||
CDynamic(t);
|
||||
default:
|
||||
xerror(x);
|
||||
}
|
||||
}
|
||||
|
||||
function xtypeparams(x:Access):Array<CType> {
|
||||
var p = new Array();
|
||||
for (c in x.elements)
|
||||
p.push(xtype(c));
|
||||
return p;
|
||||
}
|
||||
|
||||
function defplat() {
|
||||
var l = new Array();
|
||||
if (curplatform != null)
|
||||
l.push(curplatform);
|
||||
return l;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user