private static IIntermediateClassMethodMember AddPushMethod(IIntermediateClassType result, IIntermediateClassFieldMember charBufferSize, IIntermediateClassFieldMember charBuffer, IIntermediateClassMethodMember growBufferMethod, IIntermediateCliManager identityManager) { /* * * Full Method: * if (buffer == null) * GrowBuffer(2); * else if (buffer.Length < actualSize + 1) * GrowBuffer(actualSize + 1); * buffer[actualSize] = c; * actualSize++; * */ IIntermediateClassMethodMember pushMethod = result.Methods.Add(new TypedName("Push", identityManager.ObtainTypeReference(RuntimeCoreType.VoidType))); pushMethod.AccessLevel = AccessLevelModifiers.Public; var cParameter = pushMethod.Parameters.Add(new TypedName("c", identityManager.ObtainTypeReference(RuntimeCoreType.Char))); // if (buffer == null) var nullCheck = pushMethod.If(charBuffer.EqualTo(IntermediateGateway.NullValue)); // GrowBuffer(2); nullCheck.Call(growBufferMethod.GetReference().Invoke(2.ToPrimitive())); // else if (buffer.Length < actualSize + 1) nullCheck.CreateNext(charBuffer.GetReference().GetProperty("Length").LessThan(charBufferSize.GetReference().Add(1.ToPrimitive()))); var rangeCheck = (IConditionBlockStatement)nullCheck.Next; // GrowBuffer(actualSize + 1); rangeCheck.Call(growBufferMethod.GetReference().Invoke(charBufferSize.GetReference().Add(1.ToPrimitive()))); // buffer[actualSize++] = c; pushMethod.Assign(charBuffer.GetReference().GetIndexer(charBufferSize.Increment()), cParameter.GetReference()); return(pushMethod); }
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; }
private void BuildGetValidSyntaxCore(ParserCompiler compiler, ParserBuilder parserBuilder, IIntermediateCliManager identityManager) { var targetClassPartial = parserBuilder.ParserClass.Parts.Add(); this._getValidSyntaxMethodImpl = targetClassPartial.Methods.Add(new TypedName("GetValidSyntax", compiler.LexicalSymbolModel.ValidSymbols)); this._getValidSyntaxMethod = parserBuilder.ParserInterface.Methods.Add(new TypedName("GetValidSyntax", compiler.LexicalSymbolModel.ValidSymbols)); this._getValidSyntaxMethodInternalImpl = targetClassPartial.Methods.Add( new TypedName("GetValidSyntaxInternal", compiler.LexicalSymbolModel.ValidSymbols), new TypedNameSeries( new TypedName("state", RuntimeCoreType.Int32, identityManager), new TypedName("ruleContext", compiler.RuleSymbolBuilder.ILanguageRuleSymbol), new TypedName("initialPass", RuntimeCoreType.Boolean, identityManager))); }
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); }
private void BuildCullAmbiguitiesCore(ParserCompiler compiler, ParserBuilder parserBuilder, IIntermediateCliManager identityManager) { bool lexicallyAmbiguousModel = compiler._GrammarSymbols.AmbiguousSymbols.Count() > 0; if (!lexicallyAmbiguousModel) { return; } this._cullAmbiguities = this._getValidSyntaxMethodInternalImpl .Parent .Methods .Add( new TypedName("CullAmbiguitiesFrom", compiler.LexicalSymbolModel.ValidSymbols), new TypedNameSeries( new TypedName("unambiguousSource", compiler.LexicalSymbolModel.ValidSymbols))); var allAmbiguities = compiler.LexicalSymbolModel.GenerateSymbolstoreVariation(new GrammarVocabulary(compiler.GrammarSymbols, compiler._GrammarSymbols.AmbiguousSymbols.ToArray()), "AllAmbiguities", string.Format("Returns a @s:{0}; value that represents all ambiguous identities.", compiler.LexicalSymbolModel.ValidSymbols.Name)); allAmbiguities.Name = "AllAmbiguities"; this._AllAmbiguitiesField = allAmbiguities; _cullAmbiguities.AccessLevel = AccessLevelModifiers.Public; }
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; } }
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); }
public IndexerDependentParameter(ParameterMembersDictionary.ParameterMember original, IIntermediateClassMethodMember parent) : base(original, parent) { }
public IndexerValueParameter(IndexerMember owner, IIntermediateClassMethodMember parent) : base(owner, parent) { }
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 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); } }
/// <summary><para>Creates a C♯ compiler warning, relative to the abstract model, (level 4) #28:</para><para>{0} has the wrong signature to be an entry point </para></summary> /// <param name="method">The <see cref="IIntermediateClassMethodMember"/></param> public static ICompilerSourceModelWarning <IIntermediateClassMethodMember> WarningCS0028(IIntermediateClassMethodMember method) { //ToDo: Add location information to methods. return(new CompilerSourceModelWarning <IIntermediateClassMethodMember>(CS0028, method, null, LineColumnPair.Zero, LineColumnPair.Zero, method.UniqueIdentifier.ToString())); }
internal IndexerDependentParameter(ParameterMembersDictionary.ParameterMember original, IIntermediateClassMethodMember parent) : base(parent) { this.original = original; }
internal IndexerValueParameter(IntermediateClassIndexerMember <TInstanceIntermediateType> owner, IIntermediateClassMethodMember parent) : base(parent) { this.owner = owner; }