Better handling of binding when dealing with unknown userdata

This commit is contained in:
Deukhoofd 2019-01-23 13:40:10 +01:00
parent faaca91265
commit 364e71198e
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
6 changed files with 37 additions and 41 deletions

View File

@ -88,19 +88,6 @@ namespace Upsilon.BaseTypes
}
}
/*
internal class IgnoredUserDataTypeContainer : TypeContainer
{
public IgnoredUserDataTypeContainer() : base(BaseTypes.Type.Unknown)
{
Type = Type.UserData;
}
public IgnoredUserDataTypeContainer(string userData) : base(userData)
{
}
}*/
public class UndefinedUserDataTypeContainer : TypeContainer
{
private System.Type RealType { get; set; }
@ -143,10 +130,11 @@ namespace Upsilon.BaseTypes
public class CompositeTypeContainer : TypeContainer
{
public ImmutableArray<TypeContainer> Types { get; set; }
public ImmutableArray<TypeContainer> Types { get; }
public CompositeTypeContainer() : base(Type.Table)
public CompositeTypeContainer(ImmutableArray<TypeContainer> types) : base(Type.Table)
{
Types = types;
}
public override string ToString()

View File

@ -145,27 +145,20 @@ namespace Upsilon.BaseTypes
if (t.IsArray)
{
var elementType = t.GetElementType();
return new CompositeTypeContainer()
{
Types = new TypeContainer[]{Type.Number, GetScriptType(elementType)}.ToImmutableArray()
};
return new CompositeTypeContainer(new TypeContainer[] {Type.Number, GetScriptType(elementType)}
.ToImmutableArray());
}
if (typeof(IList).IsAssignableFrom(t))
{
var generic = t.GetGenericArguments()[0];
return new CompositeTypeContainer()
{
Types = new TypeContainer[]{Type.Number, GetScriptType(generic)}.ToImmutableArray()
};
return new CompositeTypeContainer(new TypeContainer[] {Type.Number, GetScriptType(generic)}
.ToImmutableArray());
}
if (typeof(IDictionary).IsAssignableFrom(t))
{
var key = t.GetGenericArguments()[0];
var value = t.GetGenericArguments()[1];
return new CompositeTypeContainer()
{
Types = new[]{GetScriptType(key), GetScriptType(value)}.ToImmutableArray()
};
return new CompositeTypeContainer(new[] {GetScriptType(key), GetScriptType(value)}.ToImmutableArray());
}
if (typeof(IEnumerable).IsAssignableFrom(t))
return Type.Table;

View File

@ -88,10 +88,9 @@ namespace Upsilon.BaseTypes.UserData
}
}
public override TypeContainer Type => new CompositeTypeContainer()
{
Types = new TypeContainer[]{BaseTypes.Type.Number, new TypeContainer(TypeName)}.ToImmutableArray()
};
public override TypeContainer Type =>
new CompositeTypeContainer(new TypeContainer[] {BaseTypes.Type.Number, new TypeContainer(TypeName)}
.ToImmutableArray());
public override object ToCSharpObject()
{
return List;

View File

@ -365,6 +365,10 @@ namespace Upsilon.Binder
if (parent.Properties.TryGetValue(fullStopIndexExpression.Index.ToLowerInvariant(),
out var bDefProperty))
{
var userData = bDefProperty.Type.UserData;
if (string.IsNullOrEmpty(userData))
return new VariableSymbol(fullStopIndexExpression.Index, Type.Unknown, true);
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.Type.UserData ?? bDefProperty.ActualType);
if (boundDef != null)
{
@ -437,9 +441,13 @@ namespace Upsilon.Binder
{
if (expression.Type == Type.UserData)
{
var boundDef = BoundTypeHandler.GetTypeDefinition(expression.Type.UserData);
var ud = expression.Type.UserData;
if (!string.IsNullOrEmpty(ud))
{
var boundDef = BoundTypeHandler.GetTypeDefinition(ud);
return new UserDataVariableSymbol("", boundDef, true);
}
}
return new VariableSymbol("", expression.Type, true);
}
else if (expression.Type == Type.Unknown)
@ -495,7 +503,7 @@ namespace Upsilon.Binder
else if (assignment.Type == Type.UserData)
{
var ud = assignment.Type.UserData;
if (ud == null)
if (string.IsNullOrEmpty(ud))
{
variable = new VariableSymbol(name, Type.Unknown, isLocal);
}
@ -1008,10 +1016,18 @@ namespace Upsilon.Binder
var type = composite.Types[1];
if (type == Type.UserData)
{
var ud = type.UserData;
if (ud == null)
{
valueVariable = new VariableSymbol(valueVar.Name, Type.Unknown, true);
}
else
{
valueVariable = new UserDataVariableSymbol(valueVar.Name,
BoundTypeHandler.GetTypeDefinition(type.UserData), true);
}
}
else if (type == Type.Table)
{
valueVariable = new TableVariableSymbol(valueVar.Name, true, composite.Types[1]);

View File

@ -51,10 +51,7 @@ namespace Upsilon.Binder
valueRealType = valueType;
var arr = new TypeContainer[] {BaseTypes.Type.String, valueRealType};
return new CompositeTypeContainer()
{
Types = arr.ToImmutableArray()
};
return new CompositeTypeContainer(arr.ToImmutableArray());
}
}

View File

@ -42,7 +42,10 @@ namespace Upsilon.Binder.VariableSymbols
var variable = Binder.ResolveVariable(callingParameter, null);
if (variable != null && variable.TypeContainer == Type.UserData)
{
if (!string.Equals(functionParameter.TypeContainer.UserData,
var userData = functionParameter.TypeContainer.UserData;
if (string.IsNullOrEmpty(userData))
continue;
if (!string.Equals(userData,
callingParameter.Type.UserData))
{
isValid = false;