public static void ValidateTypeNameVariance(this INameReference @this, ComputationContext ctx, VarianceMode typeNamePosition) { if ([email protected](ctx, @this, typeNamePosition)) { ctx.AddError(ErrorCode.VarianceForbiddenPosition, @this); } }
public static FunctionBuilder CreateDeclaration( string name, ExpressionReadMode callMode, INameReference result) { return(Create(name, callMode, result, (Block)null)); }
private VariableDeclaration(EntityModifier modifier, ExpressionReadMode readMode, string name, INameReference typeName, IExpression initValue, IEnumerable <LabelReference> friends = null) : base(readMode) { if (name == null) { throw new ArgumentNullException(); } this.Modifier = modifier ?? EntityModifier.None; this.Name = NameDefinition.Create(name); this.TypeName = typeName; this.initValue = initValue; this.AccessGrants = (friends ?? Enumerable.Empty <LabelReference>()).StoreReadOnly(); this.instancesCache = new EntityInstanceCache(this, () => GetInstance(TypeMutability.None, TemplateTranslation.CreateParameterless(this), Lifetime.Timeless)); this.closures = new List <TypeDefinition>(); this.attachPostConstructor(); this.flow = Later.Create(() => ExecutionFlow.CreatePath(InitValue)); }
public static IExpression CreateForEach(string varName, INameReference varTypeName, IExpression iterable, IEnumerable <IExpression> body) { string iter_name = AutoName.Instance.CreateNew("iter"); VariableDeclaration iter_decl = VariableDeclaration.CreateStatement(iter_name, null, FunctionCall.Create(NameReference.Create(iterable, NameFactory.IterableGetIterator))); IExpression condition; if (varName == NameFactory.Sink) { condition = ExpressionFactory.OptionalAssignment(NameFactory.SinkReference(), FunctionCall.Create(NameReference.Create(iter_name, NameFactory.IteratorNext))); } else { string elem_name = AutoName.Instance.CreateNew("elem"); body = VariableDeclaration.CreateStatement(varName, varTypeName, NameReference.Create(elem_name)) .Concat(body); condition = ExpressionFactory.OptionalDeclaration(elem_name, varTypeName, FunctionCall.Create(NameReference.Create(iter_name, NameFactory.IteratorNext))); } return(create(null, new[] { iter_decl }, preCondition: condition, body: body, postStep: null, postCondition: null)); }
private FunctionParameter(ExpressionReadMode readMode, string name, INameReference typeName, Variadic variadic, IExpression defaultValue, EntityModifier modifier, bool isNameRequired) { this.UsageMode = readMode; this.Modifier = modifier ?? EntityModifier.None; this.Name = NameDefinition.Create(name); this.IsNameRequired = isNameRequired; this.Variadic = variadic; this.ElementTypeName = typeName; if (this.IsVariadic) { this.TypeName = NameFactory.ReferenceNameReference(NameFactory.ISequenceNameReference(this.ElementTypeName, mutability: TypeMutability.ForceMutable)); } else { this.TypeName = this.ElementTypeName; } this.defaultValue = defaultValue; this.instancesCache = new EntityInstanceCache(this, () => GetInstance(TypeMutability.None, TemplateTranslation.CreateParameterless(this), Lifetime.Timeless)); this.attachPostConstructor(); }
public static FunctionDefinition CreateAutoGetter(string autoFieldName, INameReference typeName, EntityModifier modifier = null) { return(CreateGetter(typeName, Block.CreateStatement(Return.Create(NameReference.CreateThised(autoFieldName))), EntityModifier.AutoGenerated | modifier)); }
public override void Evaluate(ComputationContext ctx) { // in theory we would like to write legal code like // (*local_int_ptr) = 1 // but the problem is dereference can be seen as omitting setter (property or special functions) logic // so for now we disable it, and see when for the first time it will be needed in practice // note: swap function does not count since we already have parallel assignments // // and one more small thing, without dereference there is no ambiguity here // ref = value // does it mean (*ref) = value or ref = &value if (!ctx.Env.Options.AllowDereference) { throw new InvalidOperationException(); } if (this.Evaluation == null) { if (!ctx.Env.Dereferenced(Expr.Evaluation.Components, out IEntityInstance inner_comp)) { ctx.AddError(ErrorCode.DereferencingValue, this.Expr); } ctx.Env.Dereferenced(Expr.Evaluation.Aggregate, out IEntityInstance inner_aggr); this.typename = inner_comp.NameOf; this.typename.AttachTo(this); this.typename.Evaluated(ctx, EvaluationCall.AdHocCrossJump); this.Evaluation = EvaluationInfo.Create(inner_comp, inner_aggr.Cast <EntityInstance>()); } }
public static FunctionBuilder Create( string name, IEnumerable <TemplateParameter> nameParameters, INameReference result, Block body) { return(Create(name, nameParameters, ExpressionReadMode.ReadRequired, result, body)); }
public static FunctionParameter Create(string name, INameReference typeName, Variadic variadic, IExpression defaultValue, bool isNameRequired = false, ExpressionReadMode usageMode = ExpressionReadMode.ReadRequired) { return(new FunctionParameter(usageMode, name, typeName, variadic, defaultValue, null, isNameRequired: isNameRequired)); }
public static Property Create(IOptions options, string name, INameReference typeName, IEnumerable <VariableDeclaration> fields, IEnumerable <FunctionDefinition> getters, IEnumerable <FunctionDefinition> setters, EntityModifier modifier = null) { return(new Property(options, modifier, name, null, typeName, fields, getters, setters)); }
public static FunctionBuilder Create( string name, string nameParameter, VarianceMode variance, INameReference result, Block body) { return(Create(name, TemplateParametersBuffer.Create(variance, nameParameter).Values, result, body)); }
public void AddReference(INameReference reference) { if (reference != null) { m_referenceTable.Add(reference); OuterField?.AddReference(reference); } }
public static FunctionDefinition CreateIndexerGetter(INameReference propertyTypeName, IEnumerable <FunctionParameter> parameters, EntityModifier modifier, Block body) { return(FunctionBuilder.Create(NameFactory.PropertyGetter, ExpressionReadMode.ReadRequired, propertyTypeName, body) .SetModifier(EntityModifier.Accessor | modifier) .Parameters(parameters)); }
public static void ValidateHeapTypeName(this INameReference typeName, ComputationContext ctx, IOwnedNode errorNode = null) { if (typeName.Evaluation.Components.EnumerateAll() .Where(it => !ctx.Env.IsPointerOfType(it) && !ctx.Env.IsReferenceOfType(it)) .Any(it => it.TargetType.Modifier.HasHeapOnly)) { ctx.AddError(ErrorCode.HeapTypeAsValue, errorNode ?? typeName); } }
public bool IsExactlySame(INameReference other, EntityInstance translationTemplate, bool jokerMatchesAll) { if (!jokerMatchesAll) { return(this == other); } return(hasSymmetricRelation(other, (a, b) => a.IsExactlySame(b, translationTemplate, jokerMatchesAll))); }
internal static FunctionDefinition CreateGetter(INameReference typeName, Block body, EntityModifier modifier = null) { return(FunctionDefinition.CreateFunction(EntityModifier.Accessor | modifier, NameDefinition.Create(NameFactory.PropertyGetter), null, null, ExpressionReadMode.ReadRequired, typeName, body)); }
public static FunctionBuilder Create( string name, IEnumerable <TemplateParameter> nameParameters, ExpressionReadMode callMode, INameReference result, Block body) { return(new FunctionBuilder(name, nameParameters, null, callMode, result, body)); }
public static FunctionBuilder Create( string name, INameReference result, Block body) { return(new FunctionBuilder(name, null, null, ExpressionReadMode.ReadRequired, result, body)); }
public static Property CreateIndexer(IOptions options, INameReference typeName, IEnumerable <VariableDeclaration> fields, IEnumerable <FunctionDefinition> getters, IEnumerable <FunctionDefinition> setters, EntityModifier modifier = null) { return(Create(options, NameFactory.PropertyIndexerName, typeName, fields, getters, setters, modifier)); }
private void AddTypeSigReference(TypeSig typeSig, INameReference<IDnlibDef> reference) { foreach (ITypeDefOrRef type in typeSig.FindTypeRefs()) { TypeDef typeDef = type.ResolveTypeDefThrow(); if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) { service.ReduceRenameMode(typeDef, RenameMode.Letters); service.AddReference(typeDef, reference); } } }
public static FunctionDefinition CreateSetter(INameReference typeName, Block body, EntityModifier modifier = null) { return(FunctionDefinition.CreateFunction(EntityModifier.Accessor | modifier | EntityModifier.Mutable, NameDefinition.Create(NameFactory.PropertySetter), null, new[] { FunctionParameter.Create(NameFactory.PropertySetterValueParameter, typeName) }, ExpressionReadMode.OptionalUse, NameFactory.UnitNameReference(), body)); }
private ReinterpretType(IExpression lhs, INameReference rhsTypeName) : base(ExpressionReadMode.ReadRequired) { this.Lhs = lhs; this.RhsTypeName = rhsTypeName; this.attachPostConstructor(); this.flow = Later.Create(() => ExecutionFlow.CreatePath(Lhs)); }
private VariableBuilder(ExpressionReadMode readMode, string name, INameReference typeName, IExpression initValue) { this.name = name; this.readMode = readMode; this.typeName = typeName; this.initValue = initValue; }
public void AddReference(INameReference reference) { if (reference != null) { m_referenceTable.Add(reference); if (this.OuterField != null) { this.OuterField.AddReference(reference); } } }
private void AddTypeSigReference(TypeSig typeSig, INameReference <IDnlibDef> reference) { foreach (ITypeDefOrRef type in typeSig.FindTypeRefs()) { TypeDef typeDef = type.ResolveTypeDefThrow(); if (context.Modules.Contains((ModuleDefMD)typeDef.Module)) { service.ReduceRenameMode(typeDef, RenameMode.Letters); service.AddReference(typeDef, reference); } } }
public static FunctionBuilder CreateDeclaration( string name, string nameParameter, VarianceMode variance, ExpressionReadMode callMode, INameReference result) { return(new FunctionBuilder(name, TemplateParametersBuffer.Create(variance, nameParameter).Values, null, callMode, result, (Block)null)); }
public static FunctionBuilder CreateLambda(INameReference result, Block body, params FunctionParameter[] parameters) { FunctionBuilder builder = FunctionBuilder.Create(NameFactory.LambdaInvoke, ExpressionReadMode.ReadRequired, result, body); if (parameters.Any()) { builder.Parameters(parameters); } return(builder); }
public static FunctionDefinition CreateFunction( EntityModifier modifier, NameDefinition name, IEnumerable <TemplateConstraint> constraints, IEnumerable <FunctionParameter> parameters, ExpressionReadMode callMode, INameReference result, Block body) { return(new FunctionDefinition(modifier, name, (NameDefinition)null, constraints, parameters, callMode, result, constructorChainCall: null, body: body, includes: null, friends: null)); }
public static bool TryGetSingleType(this INameReference @this, out NameReference nameReference, out EntityInstance typeInstance) { nameReference = @this as NameReference; if (nameReference == null) { typeInstance = null; return(false); } else { typeInstance = nameReference.Evaluation.Components.Cast <EntityInstance>(); return(true); } }
private FunctionCall(CallMode mode, IExpression callee, IEnumerable <FunctionArgument> arguments, NameReference requestedOutcomeType) : base() { this.mode = mode; this.callee = callee; this.UserArguments = (arguments ?? Enumerable.Empty <FunctionArgument>()).Indexed().StoreReadOnlyList(); this.RequestedOutcomeTypeName = requestedOutcomeType; this.closures = new List <TypeDefinition>(); this.attachPostConstructor(); this.flow = Later.Create(() => ExecutionFlow.CreatePath(UserArguments)); }
private FunctionBuilder( string name, IEnumerable <TemplateParameter> nameParameters, IEnumerable <FunctionParameter> parameters, ExpressionReadMode callMode, INameReference result, Block body) { this.name = name; this.nameParameters = (nameParameters ?? Enumerable.Empty <TemplateParameter>()).StoreReadOnly(); this.parameters = parameters; this.callMode = callMode; this.result = result; this.body = body; }