Better handling of binding when dealing with unknown userdata
This commit is contained in:
parent
faaca91265
commit
364e71198e
|
@ -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
|
public class UndefinedUserDataTypeContainer : TypeContainer
|
||||||
{
|
{
|
||||||
private System.Type RealType { get; set; }
|
private System.Type RealType { get; set; }
|
||||||
|
@ -143,10 +130,11 @@ namespace Upsilon.BaseTypes
|
||||||
|
|
||||||
public class CompositeTypeContainer : TypeContainer
|
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()
|
public override string ToString()
|
||||||
|
|
|
@ -145,27 +145,20 @@ namespace Upsilon.BaseTypes
|
||||||
if (t.IsArray)
|
if (t.IsArray)
|
||||||
{
|
{
|
||||||
var elementType = t.GetElementType();
|
var elementType = t.GetElementType();
|
||||||
return new CompositeTypeContainer()
|
return new CompositeTypeContainer(new TypeContainer[] {Type.Number, GetScriptType(elementType)}
|
||||||
{
|
.ToImmutableArray());
|
||||||
Types = new TypeContainer[]{Type.Number, GetScriptType(elementType)}.ToImmutableArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (typeof(IList).IsAssignableFrom(t))
|
if (typeof(IList).IsAssignableFrom(t))
|
||||||
{
|
{
|
||||||
var generic = t.GetGenericArguments()[0];
|
var generic = t.GetGenericArguments()[0];
|
||||||
return new CompositeTypeContainer()
|
return new CompositeTypeContainer(new TypeContainer[] {Type.Number, GetScriptType(generic)}
|
||||||
{
|
.ToImmutableArray());
|
||||||
Types = new TypeContainer[]{Type.Number, GetScriptType(generic)}.ToImmutableArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (typeof(IDictionary).IsAssignableFrom(t))
|
if (typeof(IDictionary).IsAssignableFrom(t))
|
||||||
{
|
{
|
||||||
var key = t.GetGenericArguments()[0];
|
var key = t.GetGenericArguments()[0];
|
||||||
var value = t.GetGenericArguments()[1];
|
var value = t.GetGenericArguments()[1];
|
||||||
return new CompositeTypeContainer()
|
return new CompositeTypeContainer(new[] {GetScriptType(key), GetScriptType(value)}.ToImmutableArray());
|
||||||
{
|
|
||||||
Types = new[]{GetScriptType(key), GetScriptType(value)}.ToImmutableArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
if (typeof(IEnumerable).IsAssignableFrom(t))
|
if (typeof(IEnumerable).IsAssignableFrom(t))
|
||||||
return Type.Table;
|
return Type.Table;
|
||||||
|
|
|
@ -88,10 +88,9 @@ namespace Upsilon.BaseTypes.UserData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override TypeContainer Type => new CompositeTypeContainer()
|
public override TypeContainer Type =>
|
||||||
{
|
new CompositeTypeContainer(new TypeContainer[] {BaseTypes.Type.Number, new TypeContainer(TypeName)}
|
||||||
Types = new TypeContainer[]{BaseTypes.Type.Number, new TypeContainer(TypeName)}.ToImmutableArray()
|
.ToImmutableArray());
|
||||||
};
|
|
||||||
public override object ToCSharpObject()
|
public override object ToCSharpObject()
|
||||||
{
|
{
|
||||||
return List;
|
return List;
|
||||||
|
|
|
@ -365,6 +365,10 @@ namespace Upsilon.Binder
|
||||||
if (parent.Properties.TryGetValue(fullStopIndexExpression.Index.ToLowerInvariant(),
|
if (parent.Properties.TryGetValue(fullStopIndexExpression.Index.ToLowerInvariant(),
|
||||||
out var bDefProperty))
|
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);
|
var boundDef = BoundTypeHandler.GetTypeDefinition(bDefProperty.Type.UserData ?? bDefProperty.ActualType);
|
||||||
if (boundDef != null)
|
if (boundDef != null)
|
||||||
{
|
{
|
||||||
|
@ -437,8 +441,12 @@ namespace Upsilon.Binder
|
||||||
{
|
{
|
||||||
if (expression.Type == Type.UserData)
|
if (expression.Type == Type.UserData)
|
||||||
{
|
{
|
||||||
var boundDef = BoundTypeHandler.GetTypeDefinition(expression.Type.UserData);
|
var ud = expression.Type.UserData;
|
||||||
return new UserDataVariableSymbol("", boundDef, true);
|
if (!string.IsNullOrEmpty(ud))
|
||||||
|
{
|
||||||
|
var boundDef = BoundTypeHandler.GetTypeDefinition(ud);
|
||||||
|
return new UserDataVariableSymbol("", boundDef, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return new VariableSymbol("", expression.Type, true);
|
return new VariableSymbol("", expression.Type, true);
|
||||||
}
|
}
|
||||||
|
@ -495,7 +503,7 @@ namespace Upsilon.Binder
|
||||||
else if (assignment.Type == Type.UserData)
|
else if (assignment.Type == Type.UserData)
|
||||||
{
|
{
|
||||||
var ud = assignment.Type.UserData;
|
var ud = assignment.Type.UserData;
|
||||||
if (ud == null)
|
if (string.IsNullOrEmpty(ud))
|
||||||
{
|
{
|
||||||
variable = new VariableSymbol(name, Type.Unknown, isLocal);
|
variable = new VariableSymbol(name, Type.Unknown, isLocal);
|
||||||
}
|
}
|
||||||
|
@ -1009,8 +1017,16 @@ namespace Upsilon.Binder
|
||||||
var type = composite.Types[1];
|
var type = composite.Types[1];
|
||||||
if (type == Type.UserData)
|
if (type == Type.UserData)
|
||||||
{
|
{
|
||||||
valueVariable = new UserDataVariableSymbol(valueVar.Name,
|
var ud = type.UserData;
|
||||||
BoundTypeHandler.GetTypeDefinition(type.UserData), true);
|
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)
|
else if (type == Type.Table)
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,10 +51,7 @@ namespace Upsilon.Binder
|
||||||
valueRealType = valueType;
|
valueRealType = valueType;
|
||||||
|
|
||||||
var arr = new TypeContainer[] {BaseTypes.Type.String, valueRealType};
|
var arr = new TypeContainer[] {BaseTypes.Type.String, valueRealType};
|
||||||
return new CompositeTypeContainer()
|
return new CompositeTypeContainer(arr.ToImmutableArray());
|
||||||
{
|
|
||||||
Types = arr.ToImmutableArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,10 @@ namespace Upsilon.Binder.VariableSymbols
|
||||||
var variable = Binder.ResolveVariable(callingParameter, null);
|
var variable = Binder.ResolveVariable(callingParameter, null);
|
||||||
if (variable != null && variable.TypeContainer == Type.UserData)
|
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))
|
callingParameter.Type.UserData))
|
||||||
{
|
{
|
||||||
isValid = false;
|
isValid = false;
|
||||||
|
|
Loading…
Reference in New Issue