Handle bound types when they ar enot yet set
This commit is contained in:
parent
1955515f22
commit
ca9361cd0f
|
@ -1,12 +1,13 @@
|
|||
using System;
|
||||
using System.Collections.Immutable;
|
||||
using Upsilon.BoundTypes;
|
||||
|
||||
namespace Upsilon.BaseTypes
|
||||
{
|
||||
public class TypeContainer
|
||||
{
|
||||
public Type Type { get; }
|
||||
public string UserData { get; }
|
||||
public virtual string UserData { get; }
|
||||
|
||||
protected TypeContainer(Type t)
|
||||
{
|
||||
|
@ -20,6 +21,10 @@ namespace Upsilon.BaseTypes
|
|||
|
||||
public TypeContainer(string userData)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userData))
|
||||
{
|
||||
throw new Exception("Userdata name was null or empty. Not setting this properly will lead to issues later on.");
|
||||
}
|
||||
Type = Type.UserData;
|
||||
UserData = userData;
|
||||
}
|
||||
|
@ -72,6 +77,41 @@ namespace Upsilon.BaseTypes
|
|||
}
|
||||
}
|
||||
|
||||
public class UndefinedUserDataTypeContainer : TypeContainer
|
||||
{
|
||||
private System.Type RealType { get; set; }
|
||||
|
||||
protected UndefinedUserDataTypeContainer(Type t) : base(t)
|
||||
{
|
||||
}
|
||||
|
||||
public UndefinedUserDataTypeContainer(System.Type realType) : base("unset")
|
||||
{
|
||||
RealType = realType;
|
||||
}
|
||||
|
||||
private string _userData;
|
||||
|
||||
public override string UserData
|
||||
{
|
||||
get
|
||||
{
|
||||
var s = _userData;
|
||||
if (s != null)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
_userData = BoundTypeHandler.GetTypeName(RealType);
|
||||
if (_userData != null)
|
||||
{
|
||||
RealType = null;
|
||||
}
|
||||
return _userData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class CompositeTypeContainer : TypeContainer
|
||||
{
|
||||
public ImmutableArray<TypeContainer> Types { get; set; }
|
||||
|
|
|
@ -147,6 +147,9 @@ namespace Upsilon.BaseTypes
|
|||
|
||||
if (t == typeof(ScriptType))
|
||||
return Type.Unknown;
|
||||
var boundType = BoundTypeHandler.GetTypeName(t);
|
||||
if (boundType == null)
|
||||
return new UndefinedUserDataTypeContainer(t);
|
||||
return new TypeContainer(BoundTypeHandler.GetTypeName(t));
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,16 @@ namespace Upsilon.BaseTypes.UserData
|
|||
Value = obj;
|
||||
_typeInfo = UserDataTypeHandler.GetTypeInfo(obj.GetType());
|
||||
}
|
||||
public override TypeContainer Type => new TypeContainer(_typeInfo.BoundTypeName);
|
||||
public override TypeContainer Type
|
||||
{
|
||||
get
|
||||
{
|
||||
var typeData = _typeInfo.BoundTypeName;
|
||||
if (typeData != null)
|
||||
return new TypeContainer(typeData);
|
||||
return BaseTypes.Type.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
private object Value { get; }
|
||||
private readonly UserDataType _typeInfo;
|
||||
|
|
|
@ -370,7 +370,7 @@ namespace Upsilon.Binder
|
|||
if (parent.Properties.TryGetValue(fullStopIndexExpression.Index.ToLowerInvariant(),
|
||||
out var bDefProperty))
|
||||
{
|
||||
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.ActualType);
|
||||
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.Type.UserData ?? bDefProperty.ActualType);
|
||||
if (boundDef != null)
|
||||
{
|
||||
return new UserDataVariableSymbol(fullStopIndexExpression.Index, boundDef, true, parent);
|
||||
|
|
Loading…
Reference in New Issue