Handle bound types when they ar enot yet set

This commit is contained in:
Deukhoofd 2019-01-21 11:34:44 +01:00
parent 1955515f22
commit ca9361cd0f
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 55 additions and 3 deletions

View File

@ -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; }

View File

@ -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));
}

View File

@ -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;

View File

@ -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);