private void CreateGetEnumerator(IIntermediateClassType resultClass, IInterfaceType enumeratorTypeOfT, IInterfaceType enumeratorType, IInterfaceType enumerableType) { var enumeratorMethod = resultClass.Methods.Add(new TypedName("GetEnumerator", enumeratorTypeOfT)); enumeratorMethod.SummaryText = string.Format("Returns an @s:{0}{{T}}; that iterates through the @s:{1};.", enumeratorTypeOfT.ElementType.Name, resultClass.Name); enumeratorMethod.Return(this.InternalStreamImpl.GetReference().GetMethod(enumeratorMethod.Name).Invoke()); enumeratorMethod.AccessLevel = AccessLevelModifiers.Public; this.GetEnumeratorImpl = enumeratorMethod; /* * * Necessary evil to help disambiguate between the two * GetEnumerator variants, C# only allows exactly * TypeName.MethodName when explicitly implementing * an interface. * * * ToDo: Make abstraction provide 'LanguageSpecificQuantifier' callouts on the * declaration site of the method. * */ var enumerationMethodImpl = resultClass.Methods.Add(new TypedName("_GetEnumerator", enumeratorType)); enumerationMethodImpl.UserSpecificQualifier = enumerableType.FullName; enumerationMethodImpl.Name = enumeratorMethod.Name; enumerationMethodImpl.Implementations.Add(enumerableType); enumerationMethodImpl.Return(enumeratorMethod.GetReference().Invoke()); }
protected static void GetInheritedTypes(IReferenceType type, HashSet <IReferenceType> inheritedTypes) { Contract.Requires <ArgumentNullException>(type != null, "type"); Contract.Requires <ArgumentNullException>(inheritedTypes != null, "inheritedTypes"); List <IReferenceType> immediateBases = new List <IReferenceType>(); IClassType classtype = type as IClassType; if (classtype != null) { IClassType basetype = classtype.GetSuperclass(); if (basetype != null) { immediateBases.Add(basetype); } immediateBases.AddRange(classtype.GetInterfaces(false)); } IInterfaceType interfacetype = type as IInterfaceType; if (interfacetype != null) { immediateBases.AddRange(interfacetype.GetSuperInterfaces()); } foreach (var baseType in immediateBases) { if (inheritedTypes.Add(baseType)) { GetInheritedTypes(baseType, inheritedTypes); } } }
private static void ValidateImplementation( IComplexOutputType type, IInterfaceType implementedType, ICollection <ISchemaError> errors) { if (!IsFullyImplementingInterface(type, implementedType)) { errors.Add(NotTransitivelyImplemented(type, implementedType)); } foreach (IOutputField implementedField in implementedType.Fields) { if (type.Fields.TryGetField(implementedField.Name, out IOutputField? field)) { ValidateArguments(field, implementedField, errors); if (!IsValidImplementationFieldType(field.Type, implementedField.Type)) { errors.Add(InvalidFieldType(type, field, implementedField)); } } else { errors.Add(FieldNotImplemented(type, implementedField)); } } }
public Nothing TypeDefinition(IInterfaceType codeElement) { foreach (var member in codeElement.Members) { lookup.TryAddTacField(OrType.Make <IObjectDefiniton, IInterfaceType, ITypeOr>(codeElement), member); } return(new Nothing()); }
public static void Main() { IInterfaceType t1 = InterfaceTypeFactory.NewObjectByClassName("ClassA"); IInterfaceType t2 = InterfaceTypeFactory.NewObjectByClassName("ClassB"); IInterfaceType t3 = InterfaceTypeFactory.NewObjectByClassName("ClassC"); Console.WriteLine(t1.Message); Console.WriteLine(t2.Message); Console.WriteLine(t3.Message); }
private static bool IsQualifierTypeOrDirectlyInheritsFromIt(IInterfaceType interfaceType, ISemanticModel semanticModel) { if (interfaceType.Symbol == null) { return(false); } return(interfaceType.Symbol.Name == Names.BaseQualifierType || // Need to use TypeChecker.GetBaseTypes instead of interfaceType.ResolvedBaseTypes because the base types resolution is lazy. semanticModel.TypeChecker.GetBaseTypes(interfaceType)?.Any(type => type.Symbol?.Name == Names.BaseQualifierType) == true); }
public void ReferenceDeclaration(IInterfaceType declaration) { if (declaration is IIntermediateInterfaceType) { this.ReferenceDeclaration((IIntermediateInterfaceType)declaration); } else { this.Formatter.ReferenceDeclaration(declaration); } }
private static bool IsFullyImplementingInterface( IComplexOutputType type, IInterfaceType implementedType) { foreach (IInterfaceType?interfaceType in implementedType.Implements) { if (!type.IsImplementing(interfaceType)) { return(false); } } return(true); }
//public IFrontendGenericType GenericTypeDefinition(IGenericInterfaceDefinition _) //{ // throw new NotImplementedException(); // //if (backing.TryGetValue(codeElement, out var res)) // //{ // // return res; // //} // //else // //{ // // var op = new WeakGenericTypeDefinition(,,); // // backing.Add(codeElement, op); // // return op; // //} //} public IFrontendType <IVerifiableType> TypeDefinition(IInterfaceType _) { throw new NotImplementedException(); //if (backing.TryGetValue(codeElement, out var res)) //{ // return res; //} //else //{ // var op = new WeakTypeDefinition(,); // backing.Add(codeElement, op); // return op; //} }
public IInterpetedOperation <IInterpetedAnyType> TypeDefinition(IInterfaceType codeElement) { if (backing.TryGetValue(codeElement, out var res)) { return(res); } else { var op = new InterpetedTypeDefinition(); backing.Add(codeElement, op); op.Init(); return(op); } }
private static void CheckAllowedTypeReference(ITypeNode node, ISemanticModel semanticModel, DiagnosticContext context) { var type = semanticModel.GetTypeAtLocation(node); // The resolved type should be an interface IInterfaceType interfaceType = type.As <IInterfaceType>(); if (interfaceType == null) { // We already checked this is not a type literal at this point context.Logger.QualifierTypeShouldBeAnInterfaceOrTypeLiteral( context.LoggingContext, node.LocationForLogging(context.SourceFile)); return; } // The resolved type should be the special 'Qualifier' type or directly inherit from it if (!IsQualifierTypeOrDirectlyInheritsFromIt(interfaceType, semanticModel)) { context.Logger.QualifierInterfaceTypeShouldBeOrInheritFromQualifier( context.LoggingContext, node.LocationForLogging(context.SourceFile), Names.BaseQualifierType); return; } // All declarations need to be type-literal like var resolvedType = interfaceType.As <IResolvedType>(); Contract.Assert(resolvedType != null); if (resolvedType.Properties == null) { return; } foreach (var property in resolvedType.Properties) { CheckResolvedPropertyIsAnAllowedType(property, semanticModel, context); } }
public override void ImplementMethodBodyPropertyGroup( VisitorImplementationVariationPropertyGroupContext groupContext, VisitorImplementationVariationContext context, VisitorImplementationVariationPropertiesContext visitorPropertiesContext, IInterfaceType visitorInterface, IInterfaceMethodMember interfaceMethod, IIntermediateClassMethodMember concreteVariant, IVisitorImplementationBuilder implementationBuilder) { switch (groupContext.GroupId) { case "IntermediateGenericParameter": concreteVariant.Literal(string.Format("#region {0}", groupContext.GroupId)); base.ImplementMethodBodyPropertyGroup(groupContext, context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder); concreteVariant.Literal(string.Format("#endregion //{0}", groupContext.GroupId)); break; case "IntermediateInterface": case "IntermediateInstantiable": concreteVariant.Literal(string.Format("#region {0}", groupContext.GroupId)); var target = concreteVariant.If(implementationBuilder.ResultVisitorClass.GetThis().GetField("allowPartials")); var initParam = concreteVariant.Parameters.Values[0].GetReference(); target.CreateNext(initParam.GetProperty("IsRoot")); var targetNext = target.Next; target = target.If(initParam.GetProperty("HasMembers")); var targetEnumerable = target.Enumerate("member", initParam.GetProperty("Members").GetMethod("ExclusivelyOnParent").Invoke(initParam)); var targetEnumerableNullCheck = targetEnumerable.If(targetEnumerable.Local.GetReference().GetProperty("Value").GetProperty("Entry").InequalTo(IntermediateGateway.NullValue, implementationBuilder.Context.ExpressionService)); targetEnumerableNullCheck.Call(targetEnumerable.Local.GetReference().GetProperty("Value").GetProperty("Entry").GetMethod("Accept").Invoke(implementationBuilder.ResultVisitorClass.GetThis())); targetEnumerable = targetNext.Enumerate("member", initParam.GetProperty("Members").GetProperty("Values")); targetEnumerableNullCheck = targetEnumerable.If(targetEnumerable.Local.GetReference().GetProperty("Entry").InequalTo(IntermediateGateway.NullValue, implementationBuilder.Context.ExpressionService)); targetEnumerableNullCheck.Call(targetEnumerable.Local.GetReference().GetProperty("Entry").GetMethod("Accept").Invoke(implementationBuilder.ResultVisitorClass.GetThis())); concreteVariant.Literal(string.Format("#endregion //{0}", groupContext.GroupId)); break; default: base.ImplementMethodBodyPropertyGroup(groupContext, context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder); break; } }
internal static void AddInterfaceBodySteps <TAttributeGroup, TGenericParameter, TInterfaceReference, TEvent, TProperty, TIndexer, TMethod>( this List <ISourceCodeBuilderStep> steps, IInterfaceType <TAttributeGroup, TGenericParameter, TInterfaceReference, TEvent, TProperty, TIndexer, TMethod> type) where TAttributeGroup : IAttributeGroup where TGenericParameter : IGenericParameterDeclaration where TInterfaceReference : IInterfaceReference where TEvent : IInterfaceEvent where TProperty : IInterfaceProperty where TIndexer : IInterfaceIndexer where TMethod : IInterfaceMethod { ISourceCodeBuilderStep[] typeSteps = type.Events.ToSteps() .Concat(type.Properties.ToSteps()) .Concat(type.Indexers.ToSteps()) .Concat(type.Methods.ToSteps()) .ToArray(); if (typeSteps.Length != 0) { steps.Add(new WriteIndentedNewLine()); } steps.AddRange(typeSteps, () => steps.AddRange(new WriteNewLine(), new WriteIndentedNewLine())); }
public bool IsImplementing(IInterfaceType interfaceType) => interfaceType is InterfaceType i && _interfaces.IndexOf(i) != -1;
public override void ImplementMethodBodyPropertyGroup(VisitorImplementationVariationPropertyGroupContext groupContext, VisitorImplementationVariationContext context, VisitorImplementationVariationPropertiesContext visitorPropertiesContext, IInterfaceType visitorInterface, IInterfaceMethodMember interfaceMethod, IIntermediateClassMethodMember concreteVariant, IVisitorImplementationBuilder implementationBuilder) { switch (groupContext.GroupId) { case "IntermediateGenericParameter": case "IntermediateInterface": case "IntermediateInstantiable": concreteVariant.Literal(string.Format("#region {0}", groupContext.GroupId)); base.ImplementMethodBodyPropertyGroup(groupContext, context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder); concreteVariant.Literal(string.Format("#endregion //{0}", groupContext.GroupId)); break; default: break; } }
public override IIntermediateClassMethodMember CreateVariationBuilderMethod(string methodName, IGeneralGenericSignatureMemberUniqueIdentifier methodSignature, IInterfaceMethodMember interfaceMethodMember, VisitorImplementationVariationContext variation, VisitorBuilder visitorBuilder, IInterfaceType relevantBuilderInterface, IVisitorImplementationBuilder implementationBuilder) { var result = base.CreateVariationBuilderMethod(methodName, methodSignature, interfaceMethodMember, variation, visitorBuilder, relevantBuilderInterface, implementationBuilder); if (!result.IsAbstract) { result.IsVirtual = true; result.Return(result.Parameters.Values[0].GetReference()); } return(result); }
public override void ImplementMethodBody(VisitorImplementationVariationContext context, VisitorImplementationVariationPropertiesContext visitorPropertiesContext, IInterfaceType visitorInterface, IInterfaceMethodMember interfaceMethod, IIntermediateClassMethodMember concreteVariant, IVisitorImplementationBuilder implementationBuilder) { if (visitorPropertiesContext.Values.Sum(k => k.RelevantProperties.Count()) == 0) { concreteVariant.Return(GetTypeReference(implementationBuilder, typeof(TransformationImpact)).GetTypeExpression().GetField(TransformationImpact.NoImpact.ToString())); } else { base.ImplementMethodBody(context, visitorPropertiesContext, visitorInterface, interfaceMethod, concreteVariant, implementationBuilder); } }
protected override IIntermediateInterfaceMemberMapping <IStructEventMember, IIntermediateStructEventMember, IStructIndexerMember, IIntermediateStructIndexerMember, IStructMethodMember, IIntermediateStructMethodMember, IStructPropertyMember, IIntermediateStructPropertyMember, IStructType, IIntermediateStructType> OnCreateMemberMapping(IInterfaceType @interface, bool insertPlaceholders) { throw new NotImplementedException(); }
public new IIntermediateStructInterfaceMapping this[IInterfaceType @interface] { get { return((IIntermediateStructInterfaceMapping) base[@interface]); } }
public override void TranslateType(IInterfaceType interfaceType) { this.Provider.GenerateCodeFromType(interfaceType.GenerateCodeDom(this.Options), base.Target, this.Options.Options); }
public Assembly(NameKey key, IInterfaceType scope, InterpetedAssemblyBacking backing) { Key = key ?? throw new ArgumentNullException(nameof(key)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); this.Backing = backing ?? throw new ArgumentNullException(nameof(backing)); }
public static IType GetOrSetResolvedBaseConstructorType <T>(this IInterfaceType @this, T data, Func <IInterfaceType, T, IType> factory) { return(@this.ResolvedBaseConstructorType ?? (@this.ResolvedBaseConstructorType = factory(@this, data))); }
public void ReferenceDeclaration(IInterfaceType declaration) { }
public bool IsImplementing(IInterfaceType interfaceType) => interfaceType is InterfaceType i && _implements.Contains(i);
public void ReferenceDeclaration(IInterfaceType declaration) { referenceStack.Push(declaration); }
public new IIntermediateStructInterfaceMapping ImplementInterface(IInterfaceType @interface, bool insertPlaceholders = false) { return((IIntermediateStructInterfaceMapping)base.ImplementInterface(@interface, insertPlaceholders)); }
/// <summary> /// Translates an interface-based declared type. /// </summary> /// <param name="interfaceType">The <see cref="IInterfaceType"/> to translate.</param> public abstract void TranslateType(IInterfaceType interfaceType);
public IReadOnlyList <IMemberDefinition> TypeDefinition(IInterfaceType codeElement) => new List <IMemberDefinition>();
public bool IsImplementing(IInterfaceType interfaceType) => interfaceType is InterfaceType i &&
public static IReadOnlyList <IType> GetOrSetResolvedBaseTypes <T>(this IInterfaceType @this, T data, Func <IInterfaceType, T, IReadOnlyList <IType> > factory) { return(@this.ResolvedBaseTypes ?? (@this.ResolvedBaseTypes = factory(@this, data))); }