internal override LifestyleResolver <CType> GetLifestyleResolver <CType>( object syncLock, IExpressionCompiler <CType> expressionCompiler, CType testInstance) { return(new SingletonLifestyleResolver <CType>(testInstance)); }
internal override LifestyleResolver <CType> GetLifestyleResolver <CType>( object syncLock, IExpressionCompiler <CType> expressionCompiler, CType testInstance) { return(new TransientLifestyleResolver <CType>(expressionCompiler)); }
public void Configure(Action<ParsingConfiguration> configMethod) { configMethod.Invoke(_parsingContext.Configuration); _lexer = _parsingContext.Configuration.Lexer ?? _lexer; _graphBuilder = _parsingContext.Configuration.GraphBuilder ?? _graphBuilder; _compiler = _parsingContext.Configuration.ExpressionCompiler ?? _compiler; }
public void Configure(Action <ParsingConfiguration> configMethod) { configMethod.Invoke(_parsingContext.Configuration); _lexer = _parsingContext.Configuration.Lexer ?? _lexer; _graphBuilder = _parsingContext.Configuration.GraphBuilder ?? _graphBuilder; _compiler = _parsingContext.Configuration.ExpressionCompiler ?? _compiler; }
public RouteDelegateFactory(Type processorType, IMethodMapper methodMapper, IClimbStore climbStore, IExpressionCompiler compiler) { _processorType = processorType; _climbStore = climbStore; _specialMutator = new SpecialMethodMutator(processorType); _methodMapper = methodMapper; _compiler = compiler; }
public MappingGenerator(IMappingExpressionAutocompleteService mappingExpressionAutocompleteService, IExpressionCompiler expressionCompiler, IFlashMapperSettings settings) { this.mappingExpressionAutocompleteService = mappingExpressionAutocompleteService; this.expressionCompiler = expressionCompiler; this.settings = settings; }
internal override LifestyleResolver <CType> GetLifestyleResolver <CType>( object syncLock, IExpressionCompiler <CType> expressionCompiler, CType testInstance) { Func <object> instanceResolver = () => expressionCompiler.InstanceResolver(); return(new CustomLifecyleResolver <CType>(lifestyleDelegate(instanceResolver))); }
public ClimbDelegateFactory(Type processorType, IStateMemberProvider stateMemberProvider, IMethodMapper methodMapper, ClimbStore climbStore, IExpressionCompiler compiler) { _processorType = processorType; _stateMemberProvider = stateMemberProvider; _methodMapper = methodMapper; _climbStore = climbStore; _compiler = compiler; _mutator = new CallProcessMutator(_processorType, _methodMapper); }
public Resolver(Injector injector, IBindingConfig bindingConfig, object syncLock) { this.injector = injector; this.bindingConfig = bindingConfig; this.syncLock = syncLock; this.expressionCompiler = new ExpressionCompiler <CType> ( bindingConfig, injector.ResolveResolverExpression); }
public ExpressionEvaluator(IExpressionCompiler compiler, bool disableExpressionCaching) { if (compiler == null) { throw new ArgumentNullException("compiler"); } UseExpressionCache = !disableExpressionCaching; Compiler = compiler; }
/// <summary> /// Constructor /// </summary> /// <param name="expressionCompiler">Service for compiling the expressions.</param> /// <param name="entityRepository">Source of entity data, both for the calculated field metadata, and also passed into the evaluator for actual data.</param> public CalculatedFieldMetadataProvider(IExpressionCompiler expressionCompiler, IEntityRepository entityRepository) { if (expressionCompiler == null) { throw new ArgumentNullException("expressionCompiler"); } if (entityRepository == null) { throw new ArgumentNullException("entityRepository"); } _expressionCompiler = expressionCompiler; _entityRepository = entityRepository; }
/// <summary> /// Similar to <see cref="BuildResolveLambda(IExpressionCompiler, ITarget, IExpressionCompileContext)"/>, except this builds a /// lambda whose type is a strongly-typed delegate instead of object - i.e. Func{ResolveContext, T} /// </summary> /// <param name="compiler"></param> /// <param name="target"></param> /// <param name="context"></param> /// <returns></returns> public static LambdaExpression BuildResolveLambdaStrong(this IExpressionCompiler compiler, ITarget target, IExpressionCompileContext context) { if (compiler == null) { throw new ArgumentNullException(nameof(compiler)); } if (target == null) { throw new ArgumentNullException(nameof(target)); } var expression = compiler.Build(target, context); return(compiler.BuildStrongFactoryLambda(expression, context)); }
/// <summary> /// This method is a shortcut for building a lambda expression directly from an <see cref="ITarget" />. /// It calls <see cref="IExpressionCompiler.Build(ITarget, IExpressionCompileContext)" /> and passes the result to /// <see cref="IExpressionCompiler.BuildObjectFactoryLambda(Expression, IExpressionCompileContext)" />, which should yield an /// optimised lambda expression for the expression produced from the target which can then be /// compiled and used as the factory for that target. /// </summary> /// <param name="compiler">The compiler.</param> /// <param name="target">The target.</param> /// <param name="context">The current compilation context.</param> public static Expression <Func <ResolveContext, object> > BuildResolveLambda(this IExpressionCompiler compiler, ITarget target, IExpressionCompileContext context) { if (compiler == null) { throw new ArgumentNullException(nameof(compiler)); } if (target == null) { throw new ArgumentNullException(nameof(target)); } var expression = compiler.Build(target, context); return(compiler.BuildObjectFactoryLambda(expression, context)); }
public void StaticDependency_Relationships(string script, string expectedReferences) { var settings = CreateBuilderSettings("AA_Manager"); IExpressionCompiler compiler = Factory.ExpressionCompiler; IExpression expr = compiler.Compile(script, settings); CalculationDependencies dependencies = compiler.GetCalculationDependencies(expr); var expected = expectedReferences .Split(',', StringSplitOptions.RemoveEmptyEntries) .Select(alias => new EntityRef(alias).Id) .ToList(); Assert.That(dependencies.Relationships, Is.EquivalentTo(expected)); }
public override void Compile(TextWriter writer, bool isRootStatement) { IExpressionCompiler expressionCompiler = ParentStatement.MethodCallExpression.Compiler(); using (var tempVariables = Context.UseTempVariables()) { if (expressionCompiler.Type == EV3Type.Void) { expressionCompiler.Compile(writer, null); } else { expressionCompiler.Compile(writer, tempVariables.CreateVariable(expressionCompiler.Type)); } } }
public void CompileBranchForStringVariable(TextWriter writer, IExpressionCompiler valueCompiler, string label, bool negated) { if (CanCompileBoolean) { using (var tempVariables = Context.UseTempVariables()) { IEV3Variable tempResultVariable = tempVariables.CreateVariable(EV3Type.String); IEV3Variable tempIsTrueVariable = tempVariables.CreateVariable(EV3Type.Float); writer.WriteLine($" CALL IS_TRUE {valueCompiler.Compile(writer, tempResultVariable)} {tempIsTrueVariable.Ev3Name}"); writer.WriteLine($" JR_{(negated ? "EQ" : "NEQ")}8 {tempIsTrueVariable.Ev3Name} 0 {label}"); //writer.WriteLine($" STRINGS DUPLICATE {Value} {tempResultVariable.Ev3Name}"); //writer.WriteLine($" AND8888_32 {tempResultVariable.Ev3Name} -538976289 {tempResultVariable.Ev3Name}"); //writer.WriteLine($" STRINGS COMPARE {tempResultVariable.Ev3Name} 'TRUE' {tempIsTrueVariable.Ev3Name}"); //writer.WriteLine($" JR_EQ8 {tempIsTrueVariable.Ev3Name} 0 {label}"); } } }
public static int Index(this ArrayExpression arrayExpression) { int index; IExpressionCompiler expressionCompiler = arrayExpression.Indexer.Compiler(); string value = expressionCompiler.Value; if (value != null) { if (value.EndsWith(".0")) { value = value.Remove(value.Length - 2); } if (expressionCompiler.IsLiteral && int.TryParse(value, out index)) { return(index); } } return(-1); }
public override string Compile(TextWriter writer, IEV3Variable variable) { using (var tempVariables = Context.UseTempVariables()) { IExpressionCompiler indexCompiler = ParentExpression.Indexer.Compiler(); string indexValue = indexCompiler.Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); if (variable.Ev3Name.Equals(Variable.Ev3Name, StringComparison.InvariantCultureIgnoreCase) || variable.Type != Type.BaseType()) { variable = tempVariables.CreateVariable(Type.BaseType()); } if (variable.Type == EV3Type.String) { writer.WriteLine($" CALL ARRAYGET_STRING {indexValue} {variable.Ev3Name} {Variable.Ev3Name}"); } else { if (Context.DoBoundsCheck) { writer.WriteLine($" CALL ARRAYGET_FLOAT {indexValue} {variable.Ev3Name} {Variable.Ev3Name}"); } else { if (indexCompiler.IsLiteral) { if (indexValue.EndsWith(".0")) { indexValue = indexValue.Remove(indexValue.Length - 2); } } else { writer.WriteLine($" MOVEF_32 {indexValue} INDEX"); indexValue = "INDEX"; } writer.WriteLine($" ARRAY_READ {Variable.Ev3Name} {indexValue} {variable.Ev3Name}"); } } return(variable.Ev3Name); } }
public void CompileAssignment(TextWriter writer, string compiledValue, string outputName) { using (var tempVariables = Context.UseTempVariables()) { IExpressionCompiler indexCompiler = ParentExpression.Indexer.Compiler(); string indexValue = indexCompiler.Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); switch (Type.BaseType()) { case EV3Type.Int8: case EV3Type.Int16: case EV3Type.Int32: case EV3Type.Float: if (Context.DoBoundsCheck) { writer.WriteLine($" CALL ARRAYSTORE_FLOAT {indexValue} {compiledValue} {outputName}"); } else { if (indexCompiler.IsLiteral) { if (indexValue.EndsWith(".0")) { indexValue = indexValue.Remove(indexValue.Length - 2); } } else { writer.WriteLine($" MOVEF_32 {indexValue} INDEX"); indexValue = "INDEX"; } writer.WriteLine($" ARRAY_WRITE {outputName} {indexValue} {compiledValue}"); } break; case EV3Type.String: writer.WriteLine($" CALL ARRAYSTORE_STRING {indexValue} {compiledValue} {outputName}"); break; } } }
protected string CompileWithConvert(TextWriter writer, IExpressionCompiler compiler, EV3Type resultType, EV3Variables.TempVariableCreator tempVariables) { string value = compiler.Compile(writer, tempVariables.CreateVariable(compiler.Type)); if (compiler.Type.BaseType().IsNumber() && resultType.BaseType() == EV3Type.String) { if (compiler.IsLiteral) { return("'" + SmallBasicExtensions.FormatFloat(value) + "'"); } else { IEV3Variable outputVariable = tempVariables.CreateVariable(EV3Type.String); writer.WriteLine($" STRINGS VALUE_FORMATTED {value} '%g' 99 {outputVariable.Ev3Name}"); return(outputVariable.Ev3Name); } } else { return(value); } }
/// <summary> /// returns a ConstantExpression wrapped around the <see cref="ObjectTarget.Value"/> reference. /// </summary> /// <param name="target">The target whose expression is to be built.</param> /// <param name="context">The compilation context.</param> /// <param name="compiler">The expression compiler to be used to build any other expressions for targets /// which might be required by the <paramref name="target" />. Note that unlike on the interface, where this /// parameter is optional, this will always be provided</param> /// <exception cref="NotImplementedException"></exception> protected override Expression Build(ObjectTarget target, IExpressionCompileContext context, IExpressionCompiler compiler) { return(Expression.Constant(target.Value, context.TargetType ?? target.DeclaredType)); }
public GroupExpression(IExpressionCompiler expressionCompiler) { _expressionCompiler = expressionCompiler; }
public override void Compile(TextWriter writer, bool isRootStatement) { string label = Context.GetNextLabelNumber().ToString(); EV3Variable variable = Context.FindVariable(ParentStatement); if (variable.Type == EV3Type.Unknown) { variable.Type = EV3Type.Float; } variable.IsConstant = false; IExpressionCompiler stepCompiler = ParentStatement.StepValue == null ? null : ParentStatement.StepValue.Compiler(); using (var tempVariables = Context.UseTempVariables()) { string initialValue = ParentStatement.InitialValue.Compiler().Compile(writer, variable); if (initialValue != variable.Ev3Name) { writer.WriteLine($" MOVEF_F {initialValue} {variable.Ev3Name}"); } writer.WriteLine($" for{label}:"); string finalValue = ParentStatement.FinalValue.Compiler().Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); if (stepCompiler == null || stepCompiler.IsLiteral) { if (stepCompiler is NegativeExpressionCompiler) { writer.WriteLine($" JR_LTF {variable.Ev3Name} {finalValue} endfor{label}"); } else { writer.WriteLine($" JR_GTF {variable.Ev3Name} {finalValue} endfor{label}"); } } else { string stepValue = stepCompiler.Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); IEV3Variable tempStepResultVariable = tempVariables.CreateVariable(EV3Type.Float); writer.WriteLine($" CALL LE_STEP8 {variable.Ev3Name} {finalValue} {stepValue} {tempStepResultVariable.Ev3Name}"); writer.WriteLine($" JR_EQ8 {tempStepResultVariable.Ev3Name} 0 endfor{label}"); } } using (var tempVariables = Context.UseTempVariables()) { writer.WriteLine($" forbody{label}:"); ParentStatement.ForBody.Compile(writer, false); string stepValue = stepCompiler == null ? "1.0" : stepCompiler.Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); writer.WriteLine($" ADDF {variable.Ev3Name} {stepValue} {variable.Ev3Name}"); string finalValue2 = ParentStatement.FinalValue.Compiler().Compile(writer, tempVariables.CreateVariable(EV3Type.Float)); if (stepCompiler == null || stepCompiler.IsLiteral) { if (stepCompiler is NegativeExpressionCompiler) { writer.WriteLine($" JR_GTEQF {variable.Ev3Name} {finalValue2} forbody{label}"); } else { writer.WriteLine($" JR_LTEQF {variable.Ev3Name} {finalValue2} forbody{label}"); } } else { IEV3Variable tempStepResultVariable = tempVariables.CreateVariable(EV3Type.Float); writer.WriteLine($" CALL LE_STEP8 {variable.Ev3Name} {finalValue2} {stepValue} {tempStepResultVariable.Ev3Name}"); writer.WriteLine($" JR_NEQ8 {tempStepResultVariable.Ev3Name} 0 forbody{label}"); } writer.WriteLine($" endfor{label}:"); } }
/// <summary> /// Always returns a <see cref="ConstantExpression"/> which contains the <see cref="OptionalParameterTarget.Value"/>. /// </summary> /// <param name="target">The target whose expression is to be built.</param> /// <param name="context">The compilation context.</param> /// <param name="compiler">The expression compiler to be used to build any other expressions for targets /// which might be required by the <paramref name="target" />. Note that unlike on the interface, where this /// parameter is optional, this will always be provided</param> protected override Expression Build(OptionalParameterTarget target, IExpressionCompileContext context, IExpressionCompiler compiler) { // note we ignore the context requested type return(Expression.Constant(target.Value, target.DeclaredType)); }
public void Setup() { _expressionCompiler = new ExpressionCompiler(); _graph = new ExpGraph(); }
public GroupExpression(bool isNegated, IExpressionCompiler expressionCompiler) { _expressionCompiler = expressionCompiler; _isNegated = isNegated; }
public void Setup() { _expressionCompiler = new ExpressionCompiler(); _graph = new ExpGraph(); }
public EnumerableExpression(IExpressionCompiler expressionCompiler) { _expressionCompiler = expressionCompiler; }
public ParsingConfiguration SetExpresionCompiler(IExpressionCompiler expressionCompiler) { ExpressionCompiler = expressionCompiler; return this; }
public GroupExpression(bool isNegated, IExpressionCompiler expressionCompiler) { _expressionCompiler = expressionCompiler; _isNegated = isNegated; }
public DefaultGraphClimber(IStateMemberProvider stateMemberProvider, IMethodMapper methodMapper, IExpressionCompiler expressionCompiler) { _climbStore = new ClimbStore(typeof(TProcessor), stateMemberProvider, methodMapper, expressionCompiler); }
/// <summary> /// Builds the expression for the passed <paramref name="target"/> /// </summary> /// <param name="target">The target for which an expression is to be built</param> /// <param name="context">The compilation context</param> /// <param name="compiler">The compiler</param> /// <returns>An expression.</returns> protected override Expression Build(AutoFactoryTarget target, IExpressionCompileContext context, IExpressionCompiler compiler) { var(returnType, parameterTypes) = TypeHelpers.DecomposeDelegateType(context.TargetType); var compileReturnType = target.ReturnType.ContainsGenericParameters ? returnType : target.ReturnType; var newContext = context.NewContext(compileReturnType); ParameterExpression[] parameters = new ParameterExpression[0]; // if there are parameters, we have to replace any Resolve calls for the parameter types in // the inner expression with parameter expressions fed from the outer lambda if (target.ParameterTypes.Length != 0) { parameters = target.ParameterTypes.Select((pt, i) => Expression.Parameter(pt, $"p{i}")).ToArray(); foreach (var parameter in parameters) { context.RegisterExpression(parameter, parameter.Type, ScopeBehaviour.None); } } var baseExpression = compiler.BuildResolveLambda(target.Bind(newContext), newContext); var lambda = Expression.Lambda(context.TargetType, Expression.Convert(Expression.Invoke(baseExpression, context.ResolveContextParameterExpression), compileReturnType), parameters); return(lambda); }
public override void Compile(TextWriter writer, bool isRootStatement) { IAssignmentExpressionCompiler variableCompiler = ParentStatement.LeftValue.Compiler <IAssignmentExpressionCompiler>(); if (variableCompiler != null) { EV3Variable variable = Context.FindVariable(variableCompiler.VariableName); IExpressionCompiler valueCompiler = ParentStatement.RightValue.Compiler(); if (variable.Type == EV3Type.Unknown) { variable.Type = valueCompiler.Type; if (variableCompiler.IsArray) { variable.Type = variable.Type.ConvertToArray(); } } variable.IsConstant &= isRootStatement && Context.DoOptimization && valueCompiler.IsLiteral && !variable.Type.IsArray(); if (variable.Type.IsArray()) { if (valueCompiler is IAssignmentExpressionCompiler) { variable.UpdateMaxIndex(((IAssignmentExpressionCompiler)valueCompiler).Index); } else if (valueCompiler is LiteralExpressionCompiler) { variable.UpdateMaxIndex(((LiteralExpressionCompiler)valueCompiler).MaxIndex); } } //Console.WriteLine($"valueCompiler.Type = {valueCompiler.Type}, variable.Type = {variable.Type}, variableCompiler.Type = {variableCompiler.Type}"); if (variableCompiler.Type.IsArray() && (valueCompiler.Type != variableCompiler.Type)) { AddError($"Cannot assign value to array variable '{variableCompiler.VariableName}' without index"); } else if (!variableCompiler.Type.IsArray() && valueCompiler.Type.IsArray()) { AddError($"Cannot assign array value to non-array variable '{variableCompiler.VariableName}'"); } else if (valueCompiler.Type == EV3Type.String && variableCompiler.Type.IsNumber()) { AddError($"Cannot assign {valueCompiler.Type} value to {variableCompiler.Type} variable '{variableCompiler.VariableName}'"); } else if (valueCompiler.Type.IsNumber() && variableCompiler.Type == EV3Type.String && !variable.Type.IsArray()) { if (variable.IsConstant) { variable.Value = valueCompiler.Value; } else { using (var tempVariables = Context.UseTempVariables()) { IEV3Variable tempVariable = tempVariables.CreateVariable(valueCompiler.Type); string compiledValue = valueCompiler.Compile(writer, tempVariable); if (string.IsNullOrEmpty(compiledValue)) { return; } writer.WriteLine($" STRINGS VALUE_FORMATTED {compiledValue} '%g' 99 {variable.Ev3Name}"); } } } else { if (variable.IsConstant) { variable.Value = valueCompiler.Value; } else { string compiledValue = valueCompiler.Compile(writer, variable); if (string.IsNullOrEmpty(compiledValue)) { return; } using (var tempVariables = Context.UseTempVariables()) { if (valueCompiler.Type.IsNumber() && variable.Type == EV3Type.StringArray) { IEV3Variable tempVariable = tempVariables.CreateVariable(EV3Type.String); writer.WriteLine($" STRINGS VALUE_FORMATTED {compiledValue} '%g' 99 {tempVariable.Ev3Name}"); compiledValue = tempVariable.Ev3Name; } variableCompiler.CompileAssignment(writer, compiledValue, variable.Ev3Name); } } } } else { AddError($"Cannot assign value to this expression {ParentStatement.LeftValue}"); } }
public ExpressionToCodeConfiguration WithCompiler(IExpressionCompiler compiler) => With((ref ExpressionToCodeConfigurationValue a) => a.ExpressionCompiler = compiler);
/// <summary> /// Obtains the bound target for the <paramref name="target"/> passed (by calling /// <see cref="GenericConstructorTarget.Bind(ICompileContext)"/>, and passes it to the /// <paramref name="compiler"/> to have an expression built for it. /// </summary> /// <param name="target">The target whose expression is to be built.</param> /// <param name="context">The compilation context.</param> /// <param name="compiler">The expression compiler to be used to build any other expressions for targets /// which might be required by the <paramref name="target" />. Note that unlike on the interface, where this /// parameter is optional, this will always be provided</param> protected override Expression Build(GenericConstructorTarget target, IExpressionCompileContext context, IExpressionCompiler compiler) { // simply bind the generic target to the context, obtain the target that is produced // and then build it. return(compiler.Build(target.Bind(context), context)); }
public EnumerableExpression(IExpressionCompiler expressionCompiler) { _expressionCompiler = expressionCompiler; }
/// <summary> /// Creates a new instance of <see cref="Mapper"/>. /// </summary> /// <param name="expressionCompiler">The compiler to compile expressions.</param> /// <param name="mapperContext"></param> public Mapper(IExpressionCompiler expressionCompiler, MapperContext mapperContext) { ExpressionCompiler = expressionCompiler ?? throw new ArgumentNullException(nameof(expressionCompiler)); Context = mapperContext ?? throw new ArgumentNullException(nameof(mapperContext)); }
public ItIsMatcher(IExpressionCompiler expressionCompiler) { ArgumentChecker.NotNull(expressionCompiler, () => expressionCompiler); _expressionCompiler = expressionCompiler; }