Reworked type handling to handle userdata more easily
This commit is contained in:
@@ -4,19 +4,19 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
public class BoundTypeDefinition
|
||||
{
|
||||
public BoundTypeDefinition(Type scriptType, System.Type[] validInternalTypes)
|
||||
public BoundTypeDefinition(TypeContainer scriptType, System.Type[] validInternalTypes)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = validInternalTypes;
|
||||
}
|
||||
|
||||
public BoundTypeDefinition(Type scriptType, System.Type backingType)
|
||||
public BoundTypeDefinition(TypeContainer scriptType, System.Type backingType)
|
||||
{
|
||||
ScriptType = scriptType;
|
||||
ValidInternalTypes = new []{backingType};
|
||||
}
|
||||
|
||||
public Type ScriptType { get; }
|
||||
public TypeContainer ScriptType { get; }
|
||||
public System.Type[] ValidInternalTypes { get; }
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,11 @@ namespace Upsilon.BoundTypes
|
||||
return TypeDefinitions.Values.FirstOrDefault(x => x.ValidInternalTypes.Contains(type));
|
||||
}
|
||||
|
||||
public static string GetTypeName(System.Type type)
|
||||
{
|
||||
return TypeDefinitions.FirstOrDefault(x => x.Value.ValidInternalTypes.Contains(type)).Key;
|
||||
}
|
||||
|
||||
public static void LoadUserDataTypeDefinition(UserDataBoundTypeDefinition def)
|
||||
{
|
||||
var key = def.Name.ToLowerInvariant();
|
||||
|
||||
@@ -16,14 +16,14 @@ namespace Upsilon.BoundTypes
|
||||
public string Name { get; protected set; }
|
||||
public Dictionary<string, UserDataBoundProperty> Properties { get; protected set; }
|
||||
|
||||
internal UserDataBoundTypeDefinition(System.Type backingType)
|
||||
: base(Type.UserData, backingType)
|
||||
internal UserDataBoundTypeDefinition(System.Type backingType, string name)
|
||||
: base(new TypeContainer(name), backingType)
|
||||
{
|
||||
Name = backingType.Name;
|
||||
}
|
||||
|
||||
public UserDataBoundTypeDefinition(string name, Dictionary<string, UserDataBoundProperty> backingType)
|
||||
: base(Type.UserData, typeof(void))
|
||||
: base(new TypeContainer(name), typeof(void))
|
||||
{
|
||||
Name = name;
|
||||
Properties = backingType;
|
||||
@@ -33,7 +33,7 @@ namespace Upsilon.BoundTypes
|
||||
|
||||
public static UserDataBoundTypeDefinition Create(System.Type backingType, string name)
|
||||
{
|
||||
var obj = new UserDataBoundTypeDefinition(backingType)
|
||||
var obj = new UserDataBoundTypeDefinition(backingType, name)
|
||||
{
|
||||
Properties = new Dictionary<string, UserDataBoundProperty>(),
|
||||
Name = name
|
||||
@@ -101,7 +101,7 @@ namespace Upsilon.BoundTypes
|
||||
|
||||
public class UserDataBoundEnumDefinition : UserDataBoundTypeDefinition
|
||||
{
|
||||
public UserDataBoundEnumDefinition(System.Type enumType, string name) : base(enumType)
|
||||
public UserDataBoundEnumDefinition(System.Type enumType, string name) : base(enumType, name)
|
||||
{
|
||||
if (!enumType.IsEnum)
|
||||
throw new Exception("Trying to bind an enum with a type that's not an enum");
|
||||
@@ -120,7 +120,7 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
Name = valueName,
|
||||
ActualType = enumType.ToString(),
|
||||
Type = Type.UserData
|
||||
Type = new TypeContainer(name)
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,7 @@ namespace Upsilon.BoundTypes
|
||||
Properties.Add(valueName, new UserDataBoundProperty()
|
||||
{
|
||||
Name = valueName,
|
||||
Type = Type.UserData,
|
||||
Type = new TypeContainer(name),
|
||||
ActualType = name
|
||||
});
|
||||
}
|
||||
@@ -146,7 +146,7 @@ namespace Upsilon.BoundTypes
|
||||
public class UserDataBoundProperty
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public Type Type { get; set; }
|
||||
public TypeContainer Type { get; set; }
|
||||
public virtual string ActualType { get; set; }
|
||||
public string Comment { get; set; }
|
||||
}
|
||||
@@ -159,7 +159,7 @@ namespace Upsilon.BoundTypes
|
||||
public class UserDataBoundMethod: UserDataBoundProperty
|
||||
{
|
||||
public override string ActualType => "Function";
|
||||
public Type ResultType { get; set; }
|
||||
public TypeContainer ResultType { get; set; }
|
||||
public UserDataBoundFunctionParameter[] Parameters { get; set; }
|
||||
|
||||
public (bool IsValid, string Error,
|
||||
@@ -177,21 +177,21 @@ namespace Upsilon.BoundTypes
|
||||
{
|
||||
var functionParameter = Parameters[i];
|
||||
var callingParameter = callingParameters[i];
|
||||
if (callingParameter.Type == Type.Unknown || callingParameter.Type == Type.Nil)
|
||||
if (callingParameter.Type == BaseTypes.Type.Unknown || callingParameter.Type == BaseTypes.Type.Nil)
|
||||
continue;
|
||||
|
||||
if (!functionParameter.Type.HasFlag(callingParameter.Type))
|
||||
if (!functionParameter.Type.Type.HasFlag(callingParameter.Type))
|
||||
{
|
||||
return (false,
|
||||
$"Unexpected variable passed to internal function at variable {i + 1}. " +
|
||||
$"Expected one of the following: {functionParameter.Type.ToString()}, got: '{callingParameter.Type}'",
|
||||
$"Expected one of the following: {functionParameter.Type}, got: '{callingParameter.Type}'",
|
||||
callingParameter);
|
||||
}
|
||||
|
||||
if (functionParameter.Type.HasFlag(Type.UserData))
|
||||
if (functionParameter.Type.Type.HasFlag(BaseTypes.Type.UserData))
|
||||
{
|
||||
var variable = Binder.Binder.ResolveVariable(callingParameter, null);
|
||||
if (variable != null && variable.TypeContainer == Type.UserData)
|
||||
if (variable != null && variable.TypeContainer == BaseTypes.Type.UserData)
|
||||
{
|
||||
var parent =
|
||||
(UserDataBoundTypeDefinition) ((UserDataVariableSymbol) variable).BoundTypeDefinition;
|
||||
|
||||
Reference in New Issue
Block a user