final class · System.Bindings
BindingModel
public final class BindingModel
Every declaration of the binding, in the order C declared them, and its settings.
- Kind
- final class
- Namespace
- System.Bindings
- Assembly
- System.Bindings
- Access
- public, final
- Source file
Model.ant
Inheritance
- Base classes
-
AnyBindingModel
Constructors
new(BindingSettings settings)
#
Methods
static Read(BindingSettings settings, str path) : BindingModel
#
The model larva wrote to path for the profile: a declaration a line, its fields between tabs (E an enum,
M its member, T its typedef; S a struct, F its field; C a constant; U a function, P its parameter).
The function whose C symbol is entry, or null.
The struct named cName in C, or null.
The enum named cName, or null.
The constant named cName in C, or null.
An enum made from the constants whose C names match pattern (SDL_INIT_*): they leave the constants. Its
number type is the smallest that holds them; flags says whether it is a bitflag enum.
An enum made from the constants that match pattern and not except (SDL_WINDOW_*, SDL_WINDOW_SURFACE_*).
Fields
Inherited members (5)
GetTypemethod from AnyUndescribedmethod from AnyToStringmethod from AnyHashmethod from Anydestroymethod from Any
Source
BindingModel as Antril, decompiled from its Larva HIR.
// System.Bindings.BindingModel — System.Bindings (decompiled from Larva HIR)
import System;
import System.IO;
into namespace System.Bindings
{
/// Every declaration of the binding, in the order C declared them, and its settings.
public final class BindingModel
{
public:
BindingSettings Settings;
List<CFunction> Functions;
List<CStruct> Structs;
List<CEnum> Enums;
List<CConstant> Constants;
new(BindingSettings settings)
{
Functions = new List<CFunction>();
Structs = new List<CStruct>();
Enums = new List<CEnum>();
Constants = new List<CConstant>();
Settings = settings;
}
/// The model larva wrote to `path` for the profile: a declaration a line, its fields between tabs (`E` an enum,
/// `M` its member, `T` its typedef; `S` a struct, `F` its field; `C` a constant; `U` a function, `P` its parameter).
static Read(BindingSettings settings, str path) : BindingModel
{
BindingModel model = new BindingModel(settings);
CEnum lastEnum = new CEnum("", "", "i32", false);
CStruct lastStruct = new CStruct("", "", false, 0);
CFunction lastFunction = new CFunction("", "", new CType("void", ""));
{
ListIterator<str> _iterator4 = File.ReadAllLines(path).Iterator();
loop (_iterator4.Next())
{
str line = _iterator4.Current;
{
if (line.Length < 2)
continue;
List<str> f = line.Split(9);
str kind = f[0];
if (kind == "E")
lastEnum = model.AddEnum(f[1], f[2], f[3], f[4] == "1");
else if (kind == "M")
lastEnum.Add(f[1], Int64.Parse(f[2]));
else if (kind == "T")
lastEnum.Typedef(f[1]);
else if (kind == "S")
lastStruct = model.AddStruct(f[1], f[2], f[3] == "1", Int32.Parse(f[4]));
else if (kind == "F")
lastStruct.Add(f[1], f[2], f[3]);
else if (kind == "C")
model.AddConstant(f[1], f[2], Int64.Parse(f[3]));
else if (kind == "U")
lastFunction = model.AddFunction(f[1], f[2], f[3], f[4]);
else if (kind == "P")
lastFunction.Add(f[1], f[2], f[3]);
}
}
}
return model;
}
AddFunction(str entry, str header, str result, str typedef) : CFunction
{
CFunction function = new CFunction(entry, header, new CType(result, typedef));
Functions.Add(function);
return function;
}
AddStruct(str cName, str header, bool isUnion, i32 pack) : CStruct
{
CStruct structure = new CStruct(cName, header, isUnion, pack);
Structs.Add(structure);
return structure;
}
AddEnum(str cName, str header, str underlying, bool isFlags) : CEnum
{
CEnum made = new CEnum(cName, header, underlying, isFlags);
Enums.Add(made);
return made;
}
AddConstant(str cName, str header, i64 value) : CConstant
{
CConstant constant = new CConstant(cName, header, value);
Constants.Add(constant);
return constant;
}
/// The function whose C symbol is `entry`, or null.
Function(str entry) : CFunction? => Functions.Any(f => f.Entry == entry) ? Functions.First(f => f.Entry == entry) : null;
/// The struct named `cName` in C, or null.
Struct(str cName) : CStruct? => Structs.Any(s => s.CName == cName) ? Structs.First(s => s.CName == cName) : null;
/// The enum named `cName`, or null.
Enum(str cName) : CEnum? => Enums.Any(e => e.CName == cName) ? Enums.First(e => e.CName == cName) : null;
/// The constant named `cName` in C, or null.
Constant(str cName) : CConstant? => Constants.Any(c => c.CName == cName) ? Constants.First(c => c.CName == cName) : null;
/// An enum made from the constants whose C names match `pattern` (`SDL_INIT_*`): they leave the constants. Its
/// number type is the smallest that holds them; `flags` says whether it is a bitflag enum.
MakeEnum(str name, str pattern, bool flags) : CEnum => MakeEnum(name, pattern, "", flags);
/// An enum made from the constants that match `pattern` and not `except` (`SDL_WINDOW_*`, `SDL_WINDOW_SURFACE_*`).
MakeEnum(str name, str pattern, str except, bool flags) : CEnum
{
List<CConstant> taken = Constants.Where(c => Names.Matches(c.CName, pattern) && (except.Length == 0 || !Names.Matches(c.CName, except)));
CEnum made = new CEnum(name, taken.Count > 0 ? taken[0].Header : "", "i32", flags);
i64 low = 0;
i64 high = 0;
{
ListIterator<CConstant> _iterator5 = taken.Iterator();
loop (_iterator5.Next())
{
CConstant c = _iterator5.Current;
{
made.Add(c.CName, c.Value);
if (c.Value < low)
low = c.Value;
if (c.Value > high)
high = c.Value;
}
}
}
made.Underlying = low < 0 ? low >= -2147483648 && high <= 2147483647 ? "i32" : "i64" : high <= 2147483647 ? "i32" : high <= 4294967295 ? "u32" : "u64";
Constants.RemoveAll(c => Names.Matches(c.CName, pattern) && (except.Length == 0 || !Names.Matches(c.CName, except)));
Enums.Add(made);
return made;
}
}
}