private void CreateCharStreamSegment(IIntermediateAssembly assembly) { this._charStreamSegmentClass = assembly.DefaultNamespace.Parts.Add().Classes.Add("{0}CharStreamSegment", this._compiler.Source.Options.AssemblyName); this._charStreamSegmentClass.ImplementedInterfaces.ImplementInterfaceQuick(this._charStreamSegmentInterface); this.CreateStartPositionImpl(); this.CreateEndPositionImpl(); this.CreateLengthImpl(); this.CreateOwnerImpl(); this.LengthImpl.AccessLevel = this.StartPositionImpl.AccessLevel = this.EndPositionImpl.AccessLevel = AccessLevelModifiers.Public; this._StartPositionImpl.AccessLevel = this._EndPositionImpl.AccessLevel = AccessLevelModifiers.Private; this.CharStreamSegment.AccessLevel = AccessLevelModifiers.Public; }
public CharStreamClass(IIntermediateClassType bitStream, IIntermediateClassFieldMember buffer, IIntermediateClassFieldMember actualSize, IIntermediateClassMethodMember purgeMethod, IIntermediateClassMethodMember pushStringMethod, IIntermediateClassMethodMember pushCharMethod, IIntermediateClassMethodMember toStringMethod, IIntermediateClassMethodMember growBufferMethod) : base() { this.BitStream = bitStream; this.Buffer = buffer; this.ActualSize = actualSize; this.PurgeMethod = purgeMethod; this.PushStringMethod = pushStringMethod; this.PushCharMethod = pushCharMethod; this.ToStringMethod = toStringMethod; this.GrowBufferMethod = growBufferMethod; }
/// <summary> /// Determines whether the <paramref name="declaration"/> is a candidate for a module in /// the Visual Basic language. /// </summary> /// <param name="declaration">The <see cref="IIntermediateDeclaration"/> to check to see if it /// is a vb module candidate.</param> /// <returns>true if the <paramref name="declaration"/> is a valid candidate.</returns> /// <remarks>If the <paramref name="declaration"/> is a valid candidate, the translator /// will flatten the partial hierarchy using the options' <see cref="IIntermediateCodeTranslatorOptions.AllowPartials"/> property.</remarks> internal static bool DeclarationIsVBModuleCandidate(IIntermediateDeclaration declaration) { if (!(declaration is IIntermediateClassType)) { return(false); } IIntermediateClassType @class = (IIntermediateClassType)declaration; if ((@class.TypeParameters == null || @class.TypeParameters.Count == 0) && @class.SpecialModifier != SpecialClassModifier.None) { return(@class.Parent is IIntermediateNamespaceDeclaration && @class.Parts.Count == 0); } return(false); }
private static bool AnyMembers(IIntermediateClassType @class) { return(@class.BinaryOperatorCoercions.ExclusivelyOnParent().Count() > 0 || @class.Constructors.ExclusivelyOnParent().Count() > 0 || @class.Events.ExclusivelyOnParent().Count() > 0 || @class.Fields.ExclusivelyOnParent().Count() > 0 || @class.Indexers.ExclusivelyOnParent().Count() > 0 || @class.Methods.ExclusivelyOnParent().Count() > 0 || @class.Properties.ExclusivelyOnParent().Count() > 0 || @class.TypeCoercions.ExclusivelyOnParent().Count() > 0 || @class.UnaryOperatorCoercions.ExclusivelyOnParent().Count() > 0 || @class.Metadata.Count > 0 || @class.IsRoot && (@class.SummaryText != null || @class.RemarksText != null)); }
private void CreateIndexerImpl(IIntermediateClassType resultClass, IInterfaceIndexerMember initialIndexer) { var indexerFirstParam = initialIndexer.Parameters[0].Value; var indexerImpl = resultClass.Indexers.Add(new TypedName(initialIndexer.Name, initialIndexer.PropertyType), new TypedNameSeries(new TypedName(indexerFirstParam.Name, indexerFirstParam.ParameterType)), true, false); indexerImpl.SummaryText = string.Format("Returns the @t:{0}; at the @p:{1}; provided.", indexerImpl.PropertyType.Name, indexerFirstParam.Name); var indexerImplFirstParam = indexerImpl.Parameters[indexerFirstParam.UniqueIdentifier]; indexerImplFirstParam.SummaryText = string.Format("The @s:Int32; value denoting the index of the @s:{0}; to retrieve.", indexerImpl.PropertyType.Name); indexerImpl.AccessLevel = AccessLevelModifiers.Public; var indexerImplMainBlock = indexerImpl.GetMethod; indexerImplMainBlock.Return(this.InternalStreamImpl.GetReference().GetIndexer(indexerImpl.Parameters[indexerFirstParam.UniqueIdentifier].GetReference())); this.IndexerImpl = indexerImpl; }
private static IIntermediateClassMethodMember AddPushStringMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateClassMethodMember growBufferMethod, IIntermediateCliManager identityManager) { /* * * Full Method: * if (buffer == null) * GrowBuffer(s.Length); * else if (buffer.Length < actualSize + s.Length) * GrowBuffer(actualSize + s.Length); * for (int i = 0; i < s.Length; i++) * { * buffer[actualSize] = s[i]; * actualSize++; * } * */ IIntermediateClassMethodMember pushStringMethod = result.Methods.Add(new TypedName("Push", identityManager.ObtainTypeReference(RuntimeCoreType.VoidType))); pushStringMethod.AccessLevel = AccessLevelModifiers.Public; var sParameter = pushStringMethod.Parameters.Add(new TypedName("s", identityManager.ObtainTypeReference(RuntimeCoreType.String))); // if (buffer == null) var nullCheck = pushStringMethod.If(charBuffer.GetReference().EqualTo(IntermediateGateway.NullValue)); // GrowBuffer(s.Length); nullCheck.Call(growBufferMethod.GetReference().Invoke(sParameter.GetReference().GetProperty("Length"))); // else if (buffer.Length < actualSize + s.Length) nullCheck.CreateNext(charBuffer.GetReference().GetProperty("Length").LessThan(charBufferSize.GetReference().Add(sParameter.GetReference().GetProperty("Length")))); var rangeCheck = (IConditionBlockStatement)nullCheck.Next; // GrowBuffer(actualSize + s.Length); rangeCheck.Call(growBufferMethod.GetReference().Invoke(charBufferSize.GetReference().Add(sParameter.GetReference().GetProperty("Length")))); //int i = 0; var iLocal = pushStringMethod.Locals.Add(new TypedName("i", identityManager.ObtainTypeReference(RuntimeCoreType.Int32))); //So it isn't declared in the main body. iLocal.InitializationExpression = IntermediateGateway.NumberZero; iLocal.AutoDeclare = false; //i++ // for (int i = 0; i < s.Length; i++) // { var sToBufferIterate = pushStringMethod.Iterate(iLocal.GetDeclarationStatement(), iLocal.LessThan(sParameter.GetReference().GetProperty("Length")), new IStatementExpression[] { iLocal.Increment() }); //var sToBufferIterate = pushStringMethod.Iterate(iLocal.GetDeclarationStatement(), IntermediateGateway.NumberZero, sParameter.GetReference().GetProperty("Length")); // buffer[actualSize++] = s[i]; sToBufferIterate.Assign(charBuffer.GetReference().GetIndexer(charBufferSize.Increment()), sParameter.GetReference().GetIndexer(iLocal.GetReference())); // } return(pushStringMethod); }
public string Visit(IIntermediateClassType @class, DefaultAssemblyFilenameVisitorContext context) { VisitTypeParent(@class, context); if (context.CurrentResult == null) { if (AnyMembers(@class) || @class.IsRoot) { context.CurrentResult = string.Format(@"{0}\{1}", ToBaselineNamespaceName(@class.NamespaceName, context), @class.FullName.Replace('+', '.').Substring(@class.NamespaceName.Length == 0 ? 0 : @class.NamespaceName.Length + 1)); } } else if (AnyMembers(@class)) { context.CurrentResult = context.CurrentResult.Replace(@class.Name, string.Format("[{0}]", @class.Name)); } return(context.CurrentResult); }
public CSharpAssemblyFileInfo Visit(IIntermediateClassType @class, CSharpAssemblyFileContext context) { VisitTypeParent(@class, context); if (!context.CurrentResult.YieldsFile) { if (AnyMembers(@class) || @class.IsRoot) { context.CurrentResult.FileName = string.Format(@"{0}\{1}", ToBaselineNamespaceName(@class.NamespaceName, context), @class.FullName.Replace('+', '.').Substring(@class.NamespaceName.Length == 0 ? 0 : @class.NamespaceName.Length + 1)); } } else if (AnyMembers(@class)) { context.CurrentResult.FileName = context.CurrentResult.FileName.Replace(@class.Name, string.Format("[{0}]", @class.Name)); } return(context.CurrentResult); }
public static CharStreamClass CreateBitStream(IIntermediateTypeParent parent, IIntermediateCliManager identityManager) { IIntermediateClassType result = parent.Classes.Add("CharStream"); result.AccessLevel = AccessLevelModifiers.Internal; IIntermediateClassFieldMember charBuffer = result.Fields.Add(new TypedName("buffer", identityManager.ObtainTypeReference(RuntimeCoreType.Char).MakeArray())); charBuffer.AccessLevel = AccessLevelModifiers.Internal; IIntermediateClassFieldMember charBufferSize = result.Fields.Add(new TypedName("actualSize", identityManager.ObtainTypeReference(RuntimeCoreType.Int32))); charBufferSize.AccessLevel = AccessLevelModifiers.Internal; charBufferSize.InitializationExpression = IntermediateGateway.NumberZero; var purgeMethod = AddPurgeMethod(result, charBufferSize, identityManager); var growBufferMethod = AddGrowBufferMethod(result, charBufferSize, charBuffer, identityManager); var pushStringMethod = AddPushStringMethod(result, charBufferSize, charBuffer, growBufferMethod, identityManager); var toStringMethod = AddToStringMethod(result, charBufferSize, charBuffer, identityManager); var pushCharMethod = AddPushMethod(result, charBufferSize, charBuffer, growBufferMethod, identityManager); return(new CharStreamClass(result, charBuffer, charBufferSize, purgeMethod, pushStringMethod, pushCharMethod, toStringMethod, growBufferMethod)); }
private static IIntermediateClassMethodMember AddToStringMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateCliManager identityManager) { /* * * Full method: * char[] result = new char[this.actualSize]; * for (int i = 0; i < this.actualSize; i++) * result[i] = buffer[i]; * return new string(result); * */ IIntermediateClassMethodMember toStringOverride = result.Methods.Add(new TypedName("ToString", identityManager.ObtainTypeReference(RuntimeCoreType.String))); toStringOverride.AccessLevel = AccessLevelModifiers.Public; toStringOverride.IsOverride = true; //char[] result = new char[this.actualSize]; var resultCharsInitExp = new MalleableCreateArrayDetailExpression(identityManager.ObtainTypeReference(RuntimeCoreType.Char)); resultCharsInitExp.Sizes.Add(charBufferSize.GetReference()); var resultChars = toStringOverride.Locals.Add(new TypedName("result", identityManager.ObtainTypeReference(RuntimeCoreType.Char).MakeArray()), resultCharsInitExp); var iLocal = toStringOverride.Locals.Add(new TypedName("i", identityManager.ObtainTypeReference(RuntimeCoreType.Int32))); //int i = 0; iLocal.InitializationExpression = IntermediateGateway.NumberZero; //So it isn't declared in the main body. iLocal.AutoDeclare = false; //i++ var increment = iLocal.Increment(); //for (int i = 0; i < this.actualSize; i++) var loop = toStringOverride.Iterate(iLocal.GetDeclarationStatement(), iLocal.LessThan(charBufferSize), new IStatementExpression[] { increment }); // result[i] = this.buffer[i]; loop.Assign(resultChars.GetReference().GetIndexer(iLocal.GetReference()), charBuffer.GetReference().GetIndexer(iLocal.GetReference())); //return new string(result); toStringOverride.Return(identityManager.ObtainTypeReference(RuntimeCoreType.String).GetNewExpression(resultChars.GetReference())); return(toStringOverride); }
internal static bool DeclarationIsVBModule(IIntermediateDeclaration declaration, IIntermediateCodeTranslatorOptions options) { if (!(declaration is IIntermediateClassType)) { return(false); } IIntermediateClassType @class = (IIntermediateClassType)declaration; if (@class.TypeParameters == null || @class.TypeParameters.Count == 0) { if (@class.Parent is IIntermediateNamespaceDeclaration && @class.SpecialModifier != AllenCopeland.Abstraction.Slf.Abstract.SpecialClassModifier.None) { if (options.AllowPartials) { //Basically if all other partials have no members, //Then it means that it is still a module. foreach (IIntermediateClassType ict in @class.GetRoot().Parts) { if (ict == @class) { continue; } else if (ict.Members.Count > 0 || ict.Types.Count > 0) { return(false); } } if (@class != @class.GetRoot() && @class.GetRoot().Members.Count > 0) { return(false); } } } return(true); } return(false); }
/// <summary><para>Creates a C♯ compiler warning, relative /// to the abstract model, (level 3) #282:</para> /// <para>There is no defined ordering between fields in multiple /// declarations of <paramref name="offendingClass"/>. To specify an /// ordering, all instance fields must be in the same declaration. /// </para></summary> /// <param name="offendingClass">The <see cref="IIntermediateClassType"/> /// which contains one or more partial instance which contains /// fields.</param> /// <remarks>The ordering of the fields will become inconsistent /// unless all instance fields reside within the same partial instance.</remarks> public static ICompilerModelWarning <IIntermediateClassType> WarningCS0282(IIntermediateClassType offendingClass) { //ToDo: Add location information to classes. return(new CompilerModelWarning <IIntermediateClassType>(CS0282, offendingClass, offendingClass.UniqueIdentifier.ToString())); }
public void DefineDeclaration(IIntermediateClassType declaration) { this.Formatter.DefineDeclaration(declaration); }
public void ReferenceDeclaration(IIntermediateClassType declaration) { this.Formatter.ReferenceDeclaration(declaration); }
private static IIntermediateClassMethodMember AddGrowBufferMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateCliManager identityManager) { /* * * Full Method: * if (this.buffer == null) * { * this.buffer = new char[totalSize]; * return; * } * if (this.buffer.Length >= totalSize) * return; * int pNew = this.buffer.Length * 2; * if (totalSize > pNew) * pNew = totalSize; * char[] newBuffer = new char[pNew]; * this.buffer.CopyTo(newBuffer, 0); * this.buffer = newBuffer; * */ var growBufferMethod = result.Methods.Add(new TypedName("GrowBuffer", identityManager.ObtainTypeReference(RuntimeCoreType.VoidType))); var totalSizeParameter = growBufferMethod.Parameters.Add(new TypedName("totalSize", identityManager.ObtainTypeReference(RuntimeCoreType.Int32))); // if (this.buffer == null) // { var nullCheck = growBufferMethod.If(charBuffer.GetReference().EqualTo(IntermediateGateway.NullValue)); // this.buffer = new char[totalSize]; nullCheck.Assign(charBuffer.GetReference(), new MalleableCreateArrayExpression(identityManager.ObtainTypeReference(RuntimeCoreType.Char), totalSizeParameter.GetReference())); // return; // } nullCheck.Return(); // if (this.buffer.Length >= totalSize) var needCheck = growBufferMethod.If(charBuffer.GetReference().GetProperty("Length").GreaterThanOrEqualTo(totalSizeParameter)); // return; needCheck.Return(); // int pNew = this.actualSize * 2; var pNewVar = growBufferMethod.Locals.Add(new TypedName("pNew", identityManager.ObtainTypeReference(RuntimeCoreType.Int32)), charBufferSize.Multiply(2)); //So it isn't declared automatically, thus causing a potential null reference exception. pNewVar.AutoDeclare = false; growBufferMethod.DefineLocal(pNewVar); // if (totalSize > pNew) var rangeCheck = growBufferMethod.If(totalSizeParameter.GreaterThan(pNewVar)); // pNew = totalSize; rangeCheck.Assign(pNewVar.GetReference(), totalSizeParameter.GetReference()); // char[] newBuffer = new char[pNew]; var newBufferVar = growBufferMethod.Locals.Add(new TypedName("newBuffer", identityManager.ObtainTypeReference(RuntimeCoreType.Char).MakeArray()), new MalleableCreateArrayExpression(identityManager.ObtainTypeReference(RuntimeCoreType.Char), pNewVar.GetReference())); //So newBuffer doesn't refer to pNew before it is declared. newBufferVar.AutoDeclare = false; growBufferMethod.DefineLocal(newBufferVar); // this.buffer.CopyTo(newBuffer, 0); growBufferMethod.Call(charBuffer.GetReference().GetMethod("CopyTo"). Invoke(newBufferVar.GetReference(), IntermediateGateway.NumberZero)); // this.buffer = newBuffer; growBufferMethod.Assign(charBuffer.GetReference(), newBufferVar.GetReference()); return(growBufferMethod); }
void IIntermediateTypeVisitor.Visit(IIntermediateClassType intermediateType) { this.Translate(intermediateType); }
private static IIntermediateClassMethodMember BuildMethodOn(IType returnType, IIntermediateInterfaceType visitorInterface, IType voidType, IIntermediateInterfaceMethodMember method, IIntermediateClassType ruleClass, bool skipBody = false) { var ruleVisit = ruleClass.Methods.Add( new TypedName("Accept", returnType), new TypedNameSeries(new TypedName("visitor", visitorInterface))); if (returnType.IsGenericTypeParameter) { ruleVisit.TypeParameters.Add(returnType.Name); } ruleVisit.AccessLevel = AccessLevelModifiers.Public; ruleVisit.IsOverride = true; if (!skipBody) { if (returnType != voidType) { ruleVisit.Return(method.GetReference(ruleVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This))); } else { ruleVisit.Call(method.GetReference(ruleVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This))); } } return(ruleVisit); }
private static IIntermediateClassMethodMember AddVisitMethodToClass(IType returnType, IType voidType, IIntermediateInterfaceType visitorInterface, IIntermediateClassType visitedClass, bool isAbstract, IIntermediateInterfaceMethodMember memberToVisit) { var rootVisit = visitedClass.Methods.Add( new TypedName("Accept", returnType), new TypedNameSeries(new TypedName("visitor", visitorInterface))); if (returnType.IsGenericTypeParameter) { rootVisit.TypeParameters.Add(returnType.Name); } rootVisit.SummaryText = "Invokes the appropriate overload for the current @p:visitor;."; rootVisit.AccessLevel = AccessLevelModifiers.Public; var invocation = isAbstract ? null : memberToVisit.GetReference(rootVisit.Parameters["visitor"].GetReference()).Invoke(new SpecialReferenceExpression(SpecialReferenceKind.This)); if (isAbstract) { rootVisit.IsAbstract = true; } else if (returnType != voidType) { rootVisit.Return(invocation); } else { rootVisit.Call(invocation); } return(rootVisit); }
public abstract void Translate(IIntermediateClassType intermediateType);
public void DefineDeclaration(IIntermediateClassType declaration) { }
public TestLinkerResult Visit(IIntermediateClassType @class, ICompilationContext context) { throw new NotImplementedException(); }
public void DefineDeclaration(IIntermediateClassType declaration) { this.DefineDeclaration((IIntermediateType)declaration); }
public string Visit(IIntermediateClassType @class, IntermediateNameRequestDetails context) { return(VisitIntermediateType(@class, context)); }
public IIntermediateGenericType Add(string name, TypeKindGeneric kind, params GenericParameterData[] genParamData) { if (genParamData == null) { throw new ArgumentNullException("genParamData"); } if (name == null) { throw new ArgumentNullException("name"); } IIntermediateGenericType rResult = null; var assembly = this.Parent.Assembly; switch (kind) { case TypeKindGeneric.Class: { IIntermediateClassType insertionElement = null; if (assembly != null) { IIntermediateTypeCtorLanguageService <IIntermediateClassType> classService; if (assembly.Provider.TryGetService(LanguageGuids.Services.ClassServices.ClassCreatorService, out classService)) { insertionElement = classService.New(name, this.Parent); } } if (insertionElement == null) { insertionElement = new IntermediateClassType(name, this.Parent); } if (genParamData.Length > 0) { insertionElement.TypeParameters.AddRange(genParamData); } rResult = insertionElement; this.Parent.Classes.Add(insertionElement); } break; case TypeKindGeneric.Delegate: { IIntermediateDelegateType insertionElement = null; if (assembly != null && assembly.Provider != null) { IIntermediateTypeCtorLanguageService <IIntermediateDelegateType> delegateService; if (assembly.Provider.TryGetService(LanguageGuids.Services.IntermediateDelegateCreatorService, out delegateService)) { insertionElement = delegateService.New(name, this.Parent); } } if (insertionElement == null) { insertionElement = new IntermediateDelegateType(name, this.Parent); } if (genParamData.Length > 0) { insertionElement.TypeParameters.AddRange(genParamData); } rResult = insertionElement; this.Parent.Delegates.Add(insertionElement); } break; case TypeKindGeneric.Interface: { IIntermediateInterfaceType insertionElement = null; if (assembly != null && assembly.Provider != null) { IIntermediateTypeCtorLanguageService <IIntermediateInterfaceType> interfaceService; if (assembly.Provider.TryGetService(LanguageGuids.Services.InterfaceServices.InterfaceCreatorService, out interfaceService)) { insertionElement = interfaceService.New(name, this.Parent); } } if (insertionElement == null) { insertionElement = new IntermediateInterfaceType(name, this.Parent); } if (genParamData.Length > 0) { insertionElement.TypeParameters.AddRange(genParamData); } rResult = insertionElement; this.Parent.Interfaces.Add(insertionElement); } break; case TypeKindGeneric.Struct: { IIntermediateStructType insertionElement = null; if (assembly != null && assembly.Provider != null) { IIntermediateTypeCtorLanguageService <IIntermediateStructType> structService; if (assembly.Provider.TryGetService(LanguageGuids.Services.StructServices.StructCreatorService, out structService)) { insertionElement = structService.New(name, this.Parent); } } if (insertionElement == null) { insertionElement = new IntermediateStructType(name, this.Parent); } if (genParamData.Length > 0) { insertionElement.TypeParameters.AddRange(genParamData); } rResult = insertionElement; this.Parent.Structs.Add(insertionElement); } break; default: throw new NotSupportedException(); } return(rResult); }
public void ReferenceDeclaration(IIntermediateClassType declaration) { }
public TransformationKind Visit(IIntermediateClassType @class, ITransformationContext context) { throw new NotImplementedException(); }