private static void ValidateTypeInstanceEquality() { Console.WriteLine($"{nameof(ValidateTypeInstanceEquality)}"); var inAsm = EmptyType.Create(); var otherAsm = EmptyType2.Create(); Type inAsmInterfaceType = inAsm.GetType().GetInterface(nameof(IEmptyType)); Type otherAsmInterfaceType = otherAsm.GetType().GetInterface(nameof(IEmptyType)); // Sanity checks Assert.True(inAsmInterfaceType == inAsmInterfaceType); Assert.True(inAsmInterfaceType.IsEquivalentTo(inAsmInterfaceType)); Assert.False(inAsmInterfaceType.IsEquivalentTo(inAsm.GetType())); Assert.True(otherAsmInterfaceType == otherAsmInterfaceType); Assert.True(otherAsmInterfaceType.IsEquivalentTo(otherAsmInterfaceType)); Assert.False(otherAsmInterfaceType.IsEquivalentTo(otherAsm.GetType())); // The intrinsic equality operations should fail Assert.False(inAsmInterfaceType == otherAsmInterfaceType); Assert.False(inAsmInterfaceType.Equals(otherAsmInterfaceType)); Assert.False(otherAsmInterfaceType == inAsmInterfaceType); Assert.False(otherAsmInterfaceType.Equals(inAsmInterfaceType)); // Determination of equal types requires API call Assert.True(inAsmInterfaceType.IsEquivalentTo(otherAsmInterfaceType)); Assert.True(otherAsmInterfaceType.IsEquivalentTo(inAsmInterfaceType)); }
public void SerializeEmptyType() { var et1 = new EmptyType(); var et2 = new EmptyType(); var dict = new Dictionary <string, object>(); dict.Add("a", et1); dict.Add("b", et2); var sb = new StringBuilder(); using (var writer = XmlWriter.Create(sb, null)) { writer.WriteStartElement("dict"); writer.WriteDictionary(dict); writer.WriteEndElement(); } using (var reader = XmlReader.Create(new StringReader(sb.ToString()), null)) { reader.ReadToDescendant("dict"); var newDict = reader.ReadDictionary <object>(); Assert.AreEqual(2, newDict.Count); Assert.AreNotEqual(newDict["a"], newDict["b"]); } }
private static void TestGenericInterfaceEquivalence() { Console.WriteLine($"{nameof(TestGenericInterfaceEquivalence)}"); var inAsm = EmptyType.Create(); var otherAsm = EmptyType2.Create(); Type inAsmInterfaceType = inAsm.GetType().GetInterface(nameof(IEmptyType)); Type otherAsmInterfaceType = otherAsm.GetType().GetInterface(nameof(IEmptyType)); Assert.True(typeof(IGeneric <>).MakeGenericType(inAsmInterfaceType).IsEquivalentTo(typeof(IGeneric <>).MakeGenericType(otherAsmInterfaceType))); }
private static void TestByRefEquivalence() { Console.WriteLine($"{nameof(TestByRefEquivalence)}"); var inAsm = EmptyType.Create(); var otherAsm = EmptyType2.Create(); Type inAsmInterfaceType = inAsm.GetType().GetInterface(nameof(IEmptyType)); Type otherAsmInterfaceType = otherAsm.GetType().GetInterface(nameof(IEmptyType)); Assert.IsTrue(inAsmInterfaceType.MakeByRefType().IsEquivalentTo(otherAsmInterfaceType.MakeByRefType())); }
public static int SizeOf(BaseType type) { return(type switch { ArrayType arrayType => SizeOf(arrayType.ElemType) * arrayType.Length, EmptyType _ => 0, FunctionType _ => 0, NumberType numberType => numberType.BitSize / 8, PointerType _ => 8, StructType structType => SizeOfStruct(structType), _ => throw new ArgumentOutOfRangeException(nameof(type)) });
private static void InterfaceTypesFromDifferentAssembliesAreEquivalent() { Console.WriteLine($"{nameof(InterfaceTypesFromDifferentAssembliesAreEquivalent)}"); var inAsm = EmptyType.Create(); var otherAsm = EmptyType2.Create(); AreNotSameObject((IEmptyType)inAsm, (IEmptyType)otherAsm); void AreNotSameObject(IEmptyType a, IEmptyType b) { Assert.NotEqual(a, b); } }
public void SerializeEmptyType() { var et1 = new EmptyType(); var et2 = new EmptyType(); var dict = new Dictionary<string, object>(); dict.Add("a", et1); dict.Add("b", et2); var sb = new StringBuilder(); using (var writer = XmlWriter.Create(sb, null)) { writer.WriteStartElement("dict"); writer.WriteDictionary(dict); writer.WriteEndElement(); } using (var reader = XmlReader.Create(new StringReader(sb.ToString()), null)) { reader.ReadToDescendant("dict"); var newDict = reader.ReadDictionary<object>(); Assert.AreEqual(2, newDict.Count); Assert.AreNotEqual(newDict["a"], newDict["b"]); } }
public PrimitiveTypeSymbol(EmptyType declaresDataType) : base(null, declaresDataType.Name, declaresDataType) { Name = declaresDataType.Name; }
public string VisitEmptyType(EmptyType emptyType) => "Unit";
public BaseType TypeOf(Expression expression) { if (_typeCache.ContainsKey(expression)) { return(_typeCache[expression]); } BaseType result; switch (expression) { case AssignExpression _: result = new EmptyType(); break; case BinaryExpression binaryExpression: { var l = TypeOf(binaryExpression.Left); var r = TypeOf(binaryExpression.Right); result = binaryExpression.Operator switch { OperationKind.Add => VisitNumericOperation(l, r, $"{binaryExpression.Left} and {binaryExpression.Right} are not valid addition operands"), OperationKind.Multiply => VisitNumericOperation(l, r, $"{binaryExpression.Left} and {binaryExpression.Right} are not valid multiplication operands"), }; break; } case CallExpression callExpression: { var func = TypeOf(callExpression.Function); // TODO // var args = callExpression.Params.Select(TypeOf).ToList(); if (!(func is FunctionType f)) { throw new Exception("Function must be callable"); } result = f.Result; break; } case ConstExpression constExpression: result = constExpression.Type; break; case MagicExpression _: result = new FunctionType(new StructType(new NumberType(NumberKind.SignedInteger, 64)), new EmptyType()); break; case NameExpression nameExpression: result = nameExpression.Depth switch { 1 => (_compiler.Module.Entities[_compiler.CurrentFunction] as Function)?.Type.Params, 2 => (_compiler.Module.Entities[_compiler.CurrentFunction] as Function)?.Code.Variables, _ => throw new ArgumentException(), }; break; case UnaryExpression unaryExpression: { var r = TypeOf(unaryExpression.Right); result = unaryExpression.Operator switch { OperationKind.Dereference => r is PointerType pt ? pt.To : throw new Exception("Invalid operand for dereferencing"), _ => throw new ArgumentException(), }; break; } case GetFieldExpression getFieldExpression: { var field = getFieldExpression.Field; var left = getFieldExpression.Left; if (left is NameExpression ne && ne.Depth == 0) { return((_compiler.Module.Entities[field] as Function)?.Type); } if (TypeOf(left) is StructType st) { return(st.Fields[field]); } throw new Exception($"Cannot get field {field} of struct {left}"); } default: throw new ArgumentOutOfRangeException(nameof(expression)); } _typeCache[expression] = result; return(result); }
public ObjectTypeListType() { this.transitionField = new EmptyType(); this.timeDimensionField = new EmptyType(); this.structureSetField = new EmptyType(); this.structureMapField = new EmptyType(); this.reportStructureField = new EmptyType(); this.reportPeriodTargetField = new EmptyType(); this.reportingTaxonomyMapField = new EmptyType(); this.reportingTaxonomyField = new EmptyType(); this.reportingCategoryMapField = new EmptyType(); this.reportingCategoryField = new EmptyType(); this.provisionAgreementField = new EmptyType(); this.processStepField = new EmptyType(); this.processField = new EmptyType(); this.primaryMeasureField = new EmptyType(); this.organisationUnitSchemeField = new EmptyType(); this.organisationUnitField = new EmptyType(); this.organisationSchemeMapField = new EmptyType(); this.organisationMapField = new EmptyType(); this.metadataTargetField = new EmptyType(); this.metadataStructureField = new EmptyType(); this.metadataSetField = new EmptyType(); this.metadataAttributeField = new EmptyType(); this.metadataflowField = new EmptyType(); this.measureDimensionField = new EmptyType(); this.measureDescriptorField = new EmptyType(); this.levelField = new EmptyType(); this.identifiableObjectTargetField = new EmptyType(); this.hybridCodeMapField = new EmptyType(); this.hybridCodelistMapField = new EmptyType(); this.hierarchyField = new EmptyType(); this.hierarchicalCodelistField = new EmptyType(); this.hierarchicalCodeField = new EmptyType(); this.groupDimensionDescriptorField = new EmptyType(); this.dimensionDescriptorValuesTargetField = new EmptyType(); this.dimensionDescriptorField = new EmptyType(); this.dimensionField = new EmptyType(); this.dataStructureField = new EmptyType(); this.dataSetTargetField = new EmptyType(); this.dataProviderSchemeField = new EmptyType(); this.dataProviderField = new EmptyType(); this.dataConsumerSchemeField = new EmptyType(); this.dataConsumerField = new EmptyType(); this.dataflowField = new EmptyType(); this.contentConstraintField = new EmptyType(); this.conceptSchemeMapField = new EmptyType(); this.conceptSchemeField = new EmptyType(); this.conceptMapField = new EmptyType(); this.conceptField = new EmptyType(); this.componentMapField = new EmptyType(); this.codelistMapField = new EmptyType(); this.codelistField = new EmptyType(); this.codeMapField = new EmptyType(); this.codeField = new EmptyType(); this.categorySchemeField = new EmptyType(); this.categorySchemeMapField = new EmptyType(); this.categoryField = new EmptyType(); this.categorisationField = new EmptyType(); this.attributeDescriptorField = new EmptyType(); this.attributeField = new EmptyType(); this.attachmentConstraintField = new EmptyType(); this.agencySchemeField = new EmptyType(); this.agencyField = new EmptyType(); this.anyField = new EmptyType(); }
private static void BuildEmptyType(SymbolTreeBuilder tree, EmptyType emptyType) { var symbol = new PrimitiveTypeSymbol(emptyType); tree.Add(symbol); }