Exemplo n.º 1
0
        public bool IsIdentifier()
        {
            if (_builder.IsEmpty)
            {
                return(false);
            }

            var body = _builder.Body;

            if (!VariableFactory.CheckSymbol(body[0]))
            {
                return(false);
            }

            for (var i = 1; i < body.Length; i++)
            {
                if (!VariableFactory.CheckSymbol(body[i]) &&
                    (!NumberFactory.CheckSymbol(body[i]) || body[i].Equals(NumberFactory.DecimalSeparator)))
                {
                    return(false);
                }
            }

            return(true);
        }
Exemplo n.º 2
0
        private string ConvertCapturedData()
        {
            var variables = new List <Variable>();
            var factory   = new VariableFactory();

            foreach (var data in CapturedData)
            {
                try
                {
                    var variable = factory.FromObject(data.Value);
                    variable.Name = data.Key;
                    variables.Add(variable);
                }
                catch
                {
                    // If the variable is null, the snippet above will throw an exception, so just
                    // add a dummy string variable with the literal value "null".
                    variables.Add(new StringVariable("null")
                    {
                        Name = data.Key
                    });
                }
            }

            return(string.Join(" | ", variables.Select(v => $"{v.Name} = {v.AsString()}")));
        }
Exemplo n.º 3
0
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            Source = VariableFactory.CreateScriptedVariable <long>(reader.GetAttribute("Source"));

            string modeString = reader.GetAttribute("Mode");

            if (modeString != null)
            {
                Mode = (SwitchMode)Enum.Parse(typeof(SwitchMode), modeString);
            }

            bool hasElements = !reader.IsEmptyElement;

            reader.ReadStartElement();
            if (hasElements)
            {
                while (reader.IsStartElement())
                {
                    reader.MoveToContent();
                    if (reader.Name == "Default" && Default == null)
                    {
                        Default = ReadCase(reader);
                    }
                    else
                    {
                        var c = ReadCase(reader);
                        Cases.Add(c);
                    }
                }
                reader.ReadEndElement();
            }
        }
        public void FacotryShouldNotAssignVariable()
        {
            VariableFactory factory  = new VariableFactory();
            IVariable       variable = factory.CreateNewWithGUID(Variable.VariableType.Object);

            Assert.False(variable.IsAssigned);
        }
Exemplo n.º 5
0
        public void Instantiate_CSharp_IsNotEvaluated()
        {
            var factory  = new VariableFactory();
            var resolver = new CSharpScalarResolver <object>(new CSharpScalarResolverArgs("DateTime.Now.Year"));
            var variable = factory.Instantiate(VariableScope.Global, resolver);

            Assert.That(variable.IsEvaluated, Is.False);
        }
        private void cboSource_SelectedIndexChanged(object sender, EventArgs e)
        {
            string source = cboSource.Text;

            _variable = VariableFactory.Create(source);
            this.panel1.Controls.Clear();
            this.panel1.Controls.Add(_variable.Editor);
            _variable.Editor.Dock = DockStyle.Fill;
        }
Exemplo n.º 7
0
        public void Instantiate_CSharp_GlobalVariable()
        {
            var factory  = new VariableFactory();
            var resolver = new CSharpScalarResolver <object>(new CSharpScalarResolverArgs("DateTime.Now.Year"));
            var variable = factory.Instantiate(VariableScope.Global, resolver);

            Assert.That(variable, Is.AssignableTo <ITestVariable>());
            Assert.That(variable, Is.AssignableTo <TestVariable>());
            Assert.That(variable, Is.TypeOf <GlobalVariable>());
        }
Exemplo n.º 8
0
        public void Instantiate_QueryScalar_GlobalVariable()
        {
            var factory = new VariableFactory();
            var queryResolverArgsMock = new Mock <BaseQueryResolverArgs>(null, null, null, null);
            var resolver = new QueryScalarResolver <object>(new QueryScalarResolverArgs(queryResolverArgsMock.Object), new ServiceLocator());
            var variable = factory.Instantiate(VariableScope.Global, resolver);

            Assert.That(variable, Is.AssignableTo <ITestVariable>());
            Assert.That(variable, Is.AssignableTo <TestVariable>());
            Assert.That(variable, Is.TypeOf <GlobalVariable>());
        }
Exemplo n.º 9
0
        public IVariableFactory CreateVariableFactory()
        {
            IVariableFactory factory = null;

            try
            {
                factory = new VariableFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error("Exception message: " + exception.Message + " and stacktrace " + exception.StackTrace);
            }

            return(factory);
        }
Exemplo n.º 10
0
 public StandardVariableTable(VariableFactory varFac)
 {
     base.SetVariableFactory(varFac);
     try
     {
         base.AddConstant("pi", new JepDouble(3.1415926535897931));
         base.AddConstant("e", new JepDouble(2.7182818284590451));
         base.AddConstant("i", new Complex(0.0, 1.0));
         base.AddConstant("true", true);
         base.AddConstant("false", false);
     }
     catch (JepException exception)
     {
         Console.WriteLine("Error creating standard variable table. " + exception);
     }
 }
Exemplo n.º 11
0
        private ServiceEntity(XmlElement definition)
        {
            XmlHelper h = new XmlHelper(definition);

            this.SQLTemplate      = h.GetText("SQLTemplate");
            ResponseRecordElement = h.GetText("ResponseRecordElement");
            RequestRecordElement  = h.GetText("RequestRecordElement");
            FieldList             = new FieldList(h.GetElement("FieldList"));
            ConditionList         = new ConditionList(h.GetElement("Conditions"));
            Orders     = new OrderList(h.GetElement("Orders"));
            Pagination = new Pagination(h.GetElement("Pagination"));

            ServiceAction action = ServiceAction.Select;

            if (!Enum.TryParse <ServiceAction>(h.GetText("Action"), true, out action))
            {
                action = ServiceAction.Select;
            }
            Action = action;

            this.Variables = new List <IVariable>();
            foreach (XmlElement varElement in h.GetElements("InternalVariable/Variable"))
            {
                IVariable v = VariableFactory.Parse(varElement);
                if (v != null)
                {
                    Variables.Add(v);
                }
            }

            this.Converters = new List <IConverter>();
            foreach (XmlElement cvElement in h.GetElements("Converters/Converter"))
            {
                string     type = cvElement.GetAttribute("Type");
                IConverter c    = ConverterProvider.CreateConverter(type);
                c.Load(cvElement);

                this.Converters.Add(c);
            }

            this.Preprocesses = new List <Preprocess>();
            foreach (XmlElement preElement in h.GetElements("Preprocesses/Preprocess"))
            {
                Preprocess p = Preprocess.Parse(preElement);
                this.Preprocesses.Add(p);
            }
        }
Exemplo n.º 12
0
        private IDictionary <string, ITestVariable> BuildVariables(IEnumerable <GlobalVariableXml> variables, IDictionary <string, object> overridenVariables)
        {
            var instances       = new Dictionary <string, ITestVariable>();
            var resolverFactory = serviceLocator.GetScalarResolverFactory();

            Trace.WriteLineIf(NBiTraceSwitch.TraceInfo, $"{variables.Count()} variable{(variables.Count() > 1 ? "s" : string.Empty)} defined in the test-suite.");
            var variableFactory = new VariableFactory();

            foreach (var variable in variables)
            {
                if (overridenVariables.ContainsKey(variable.Name))
                {
                    var instance = new OverridenVariable(variable.Name, overridenVariables[variable.Name]);
                    instances.Add(variable.Name, instance);
                }
                else
                {
                    var builder = new ScalarResolverArgsBuilder(serviceLocator, new Context(instances));

                    if (variable.Script != null)
                    {
                        builder.Setup(variable.Script);
                    }
                    else if (variable.QueryScalar != null)
                    {
                        variable.QueryScalar.Settings = TestSuiteManager.TestSuite.Settings;
                        variable.QueryScalar.Default  = TestSuiteManager.TestSuite.Settings.GetDefault(Xml.Settings.SettingsXml.DefaultScope.Variable);
                        builder.Setup(variable.QueryScalar, variable.QueryScalar.Settings, Xml.Settings.SettingsXml.DefaultScope.Variable);
                    }
                    else if (variable.Environment != null)
                    {
                        builder.Setup(variable.Environment);
                    }
                    else if (variable.Custom != null)
                    {
                        builder.Setup(variable.Custom);
                    }
                    builder.Build();
                    var args = builder.GetArgs();

                    var resolver = resolverFactory.Instantiate(args);
                    instances.Add(variable.Name, variableFactory.Instantiate(VariableScope.Global, resolver));
                }
            }

            return(instances);
        }
Exemplo n.º 13
0
        public IVariableFactory CreateVariableFactory()
        {
            IVariableFactory factory = null;

            try
            {
                factory = new VariableFactory();
            }
            catch (Exception exception)
            {
                this.Log.Error(
                    exception.Message,
                    exception);
            }

            return(factory);
        }
Exemplo n.º 14
0
        public override InterpreterState MoveToNextState(Symbol symbol, ILexemesStack stack, ExecutorContext context)
        {
            switch (symbol.Type)
            {
            case SymbolType.Number:
            case SymbolType.Identifier:
                if (symbol.Value.Equals(NumberFactory.DecimalSeparator))
                {
                    return(new ErrorState(symbol));
                }

                _variableBuilder.Append(symbol);
                return(this);

            case SymbolType.Operator:
                var @operator  = OperatorFactory.CreateOperator(symbol);
                var identifier = VariableFactory.CreateVariable(_variableBuilder);

                if (@operator is OpeningBracket)
                {
                    return(new FunctionSignatureStartState(identifier));
                }

                stack.Push(identifier);
                stack.Push(@operator);

                switch (@operator)
                {
                case AssignmentOperator _:
                    return(new AssignmentOperatorState());

                case ClosingBracket _:
                    return(new ClosingBracketOperatorState());

                case CommaOperator _:
                    return(new ErrorState(symbol));

                default:
                    return(new BinaryOperatorState());
                }

            default:
                return(new ErrorState(symbol));
            }
        }
Exemplo n.º 15
0
        public TrueSkillFactorGraph(GameInfo gameInfo, IEnumerable <IDictionary <TPlayer, Rating> > teams, int[] teamRanks)
        {
            _PriorLayer     = new PlayerPriorValuesToSkillsLayer <TPlayer>(this, teams);
            GameInfo        = gameInfo;
            VariableFactory =
                new VariableFactory <GaussianDistribution>(() => GaussianDistribution.FromPrecisionMean(0, 0));

            _Layers = new List <FactorGraphLayerBase <GaussianDistribution> >
            {
                _PriorLayer,
                new PlayerSkillsToPerformancesLayer <TPlayer>(this),
                new PlayerPerformancesToTeamPerformancesLayer <TPlayer>(this),
                new IteratedTeamDifferencesInnerLayer <TPlayer>(
                    this,
                    new TeamPerformancesToTeamPerformanceDifferencesLayer <TPlayer>(this),
                    new TeamDifferencesComparisonLayer <TPlayer>(this, teamRanks))
            };
        }
Exemplo n.º 16
0
        private static SymbolType GetSymbolType(char value)
        {
            if (NumberFactory.CheckSymbol(value))
            {
                return(SymbolType.Number);
            }

            if (OperatorFactory.CheckSymbol(value))
            {
                return(SymbolType.Operator);
            }

            if (VariableFactory.CheckSymbol(value))
            {
                return(SymbolType.Identifier);
            }

            return(SymbolType.Undefined);
        }
Exemplo n.º 17
0
        public override void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            string sizeString = reader.GetAttribute("Size");

            if (sizeString != null)
            {
                if (VariableFactory.IsScriptedVariable(sizeString))
                {
                    Size = VariableFactory.CreateScriptedVariable <int>(sizeString);
                }
                else
                {
                    Size = new StaticValue <int>(int.Parse(sizeString));
                }
            }
            else
            {
                Size = new DynamicArrayMarker();
            }
            base.ReadXml(reader);
        }
 public void WireUp()
 {
     VariableFactory factory = new VariableFactory();
 }
Exemplo n.º 19
0
        static XGenParser()
        {
            Factories = new Dictionary <string, VariableFactory>
            {
                { "PageViews", VariableFactory.Lambda((segment, token, parser) => segment.VisitVariables.AddOrReplace(Variables.Random("PageViews", new PoissonGenerator(token.Value <double>()).Truncate(1, 20)))) },
                { "VisitCount", VariableFactory.Lambda((segment, token, parser) => segment.VisitorVariables.AddOrReplace(Variables.Random("VisitCount", new PoissonGenerator(token.Value <double>()).Truncate(1, 20)))) },
                { "BounceRate", VariableFactory.Lambda((segment, token, parser) => segment.VisitVariables.AddOrReplace(Variables.Boolean("Bounce", token.Value <double>()))) },
                { "Duration", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var mean = token.Value <double>();
                        segment.RequestVariables.AddOrReplace(Variables.Duration(new SkewNormalGenerator(mean, mean, 3), 1));
                    }) },
                { "StartDate", VariableFactory.Lambda((segment, token, parser) => segment.DateGenerator.Start = token.Value <DateTime>()) },
                { "EndDate", VariableFactory.Lambda((segment, token, parser) => segment.DateGenerator.End = token.Value <DateTime>()) },
                { "DayOfWeek", VariableFactory.Lambda((segment, token, parser) => segment.DateGenerator.DayOfWeek(t => t.Clear().Weighted(builder =>
                    {
                        foreach (var kv in (JObject)token)
                        {
                            DayOfWeek day;
                            builder.Add(Enum.TryParse(kv.Key, out day) ? (int)day : int.Parse(kv.Key), kv.Value.Value <double>());
                        }
                    }))) },
                { "YearlyTrend", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        if (token.Value <double>() != 1)
                        {
                            segment.DateGenerator.Year(t => t.Clear().MoveAbsolutePercentage(0).LineAbsolutePercentage(1, token.Value <double>()));
                        }
                        //segment.DateGenerator.YearWeight = 1;
                    }) },
                { "Month", new MonthFactory() },
                { "Identified", VariableFactory.Lambda((segment, token, parser) => segment.VisitorVariables.AddOrReplace(new ContactDataVariable(token.Value <double>()))) },
                { "Campaign", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var campaignPct = token.Value <double?>("Percentage") ?? 1;
                        var campaigns   = parser.ParseWeightedSet <string>(token["Weights"]);
                        segment.VisitVariables.AddOrReplace(Variables.Random("Campaign", () => Randomness.Random.NextDouble() < campaignPct ? campaigns() : null, true));
                    }) },
                { "Channel", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var channelPct = token.Value <double?>("Percentage") ?? 1;
                        var channels   = parser.ParseWeightedSet <string>(token["Weights"]);
                        segment.VisitVariables.AddOrReplace(Variables.Random("Channel", () => Randomness.Random.NextDouble() < channelPct ? channels() : null, true));
                    }) },
                { "Referrer", VariableFactory.Lambda((segment, token, parser) => segment.VisitVariables.AddOrReplace(Variables.Random("Referrer", parser.ParseWeightedSet <string>(token), true))) },
                { "Geo", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var regionId = parser.ParseWeightedSet <string>(token["Region"]);
                        segment.VisitorVariables.AddOrReplace(new GeoVariables(() => new GetRandomCityService().GetRandomCity(regionId())));
                    }) },
                { "Devices", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        Func <string> userAgent;
                        if (!token.HasValues)
                        {
                            userAgent = new DeviceRepository().GetAll().Select(d => d.UserAgent).Exponential(.8, 8);
                        }
                        else
                        {
                            var id    = parser.ParseWeightedSet <string>(token);
                            userAgent = () => new DeviceRepository().GetAll().ToDictionary(ga => ga.Id, ga => ga)[id()].UserAgent;
                        }
                        segment.VisitorVariables.AddOrReplace(Variables.Random("UserAgent", userAgent));
                    }) },
                { "Outcomes", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var value = new NormalGenerator(10, 5).Truncate(1);
                        segment.VisitVariables.AddOrReplace(new OutcomeVariable(parser.ParseSet <string>(token), value.Next));
                    }) },

                { "Goal", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var goalPct = token.Value <double?>("Percentage") ?? 0.2;
                        var goals   = parser.ParseWeightedSet <string>(token["Weights"]);
                        segment.VisitVariables.AddOrReplace(Variables.Random("Goal", () => Randomness.Random.NextDouble() < goalPct ? goals() : null, true));
                    }) },

                { "InternalSearch", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var searchPct = token.Value <double?>("Percentage") ?? 0.2;
                        var keywords  = parser.ParseWeightedSet <string>(token["Keywords"]);
                        segment.VisitVariables.AddOrReplace(Variables.Random("InternalSearch", () => Randomness.Random.NextDouble() < searchPct ? keywords() : null, true));
                    }) },
                { "ExternalSearch", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var searchPct = token.Value <double?>("Percentage") ?? 0.2;
                        var keywords  = parser.ParseWeightedSet <string>(token["Keywords"]);

                        var engineId = parser.ParseWeightedSet <string>(token["Engine"]);

                        segment.VisitVariables.AddOrReplace(new ExternalSearchVariable(() => Randomness.Random.NextDouble() >= searchPct ? null : SearchEngine.SearchEngines.ToDictionary(s => s.Id)[engineId()], () => new[] { keywords() }));
                    }) },
                { "Language", VariableFactory.Lambda((segment, token, parser) =>
                    {
                        var languages = parser.ParseWeightedSet <string>(token);
                        segment.VisitVariables.AddOrReplace(Variables.Random("Language", languages));
                    }) },
                { "LandingPage", new LandingPageFactory() }
            };
        }
Exemplo n.º 20
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //property.serializedObject.Update();
            int oldIndentLevel = EditorGUI.indentLevel;

            Rect  currentRect = new Rect(position.x, position.y + LineHeight, position.width, LineHeight);
            float oldY        = currentRect.y;

            Color oldColor = GUI.backgroundColor;

            GUI.backgroundColor = Color.white;

            SerializedProperty dataTypeProperty =
                property.FindPropertyRelative(nameof(VariableFactory.DataTypesToCreate));

            EditorGUI.PropertyField(currentRect, dataTypeProperty);
            currentRect.y += LineHeight;

            SerializedProperty variableTypeProperty =
                property.FindPropertyRelative(nameof(VariableFactory.VariableTypeToCreate));

            EditorGUI.PropertyField(currentRect, variableTypeProperty);
            currentRect.y += LineHeight;

            if (GUI.Button(currentRect, "Create Variable"))
            {
                VariableFactory factory =
                    fieldInfo.GetValue(property.serializedObject.targetObject) as VariableFactory;
                factory?.AddNew();
            }
            currentRect.y      += LineHeight;
            GUI.backgroundColor = oldColor;

            property.serializedObject.ApplyModifiedProperties();



            //ADD IVs
            EditorGUI.LabelField(currentRect, "--------");
            currentRect.y += LineHeight;
            EditorGUI.LabelField(currentRect, "Independent Variables:", EditorStyles.boldLabel);
            currentRect.y += LineHeight;

            SerializedProperty intIvProperty = property.FindPropertyRelative(nameof(VariableFactory.IntIVs));

            currentRect = AddPropertyFromList(currentRect, intIvProperty);

            SerializedProperty floatsIvProperty = property.FindPropertyRelative(nameof(VariableFactory.FloatIVs));

            currentRect = AddPropertyFromList(currentRect, floatsIvProperty);

            SerializedProperty stringsIvProperty = property.FindPropertyRelative(nameof(VariableFactory.StringIVs));

            currentRect = AddPropertyFromList(currentRect, stringsIvProperty);

            SerializedProperty boolsIvProperty = property.FindPropertyRelative(nameof(VariableFactory.BoolIVs));

            currentRect = AddPropertyFromList(currentRect, boolsIvProperty);

            SerializedProperty gameObjectsIvProperty =
                property.FindPropertyRelative(nameof(VariableFactory.GameObjectIVs));

            currentRect = AddPropertyFromList(currentRect, gameObjectsIvProperty);

            SerializedProperty vector3IvProperty = property.FindPropertyRelative(nameof(VariableFactory.Vector3IVs));

            currentRect = AddPropertyFromList(currentRect, vector3IvProperty);

            SerializedProperty customDataTypesIvProperty =
                property.FindPropertyRelative(nameof(VariableFactory.CustomDataTypeIVs));

            currentRect = AddPropertyFromList(currentRect, customDataTypesIvProperty);

            //ADD DVs
            EditorGUI.LabelField(currentRect, "--------");
            currentRect.y += LineHeight;
            EditorGUI.LabelField(currentRect, "Dependent Variables:", EditorStyles.boldLabel);
            currentRect.y += LineHeight;

            SerializedProperty intDvProperty = property.FindPropertyRelative(nameof(VariableFactory.IntDVs));

            currentRect = AddPropertyFromList(currentRect, intDvProperty);

            SerializedProperty floatsDvProperty = property.FindPropertyRelative(nameof(VariableFactory.FloatDVs));

            currentRect = AddPropertyFromList(currentRect, floatsDvProperty);

            SerializedProperty stringsDvProperty = property.FindPropertyRelative(nameof(VariableFactory.StringDVs));

            currentRect = AddPropertyFromList(currentRect, stringsDvProperty);

            SerializedProperty boolsDvProperty = property.FindPropertyRelative(nameof(VariableFactory.BoolDVs));

            currentRect = AddPropertyFromList(currentRect, boolsDvProperty);

            SerializedProperty gameObjectsDvProperty =
                property.FindPropertyRelative(nameof(VariableFactory.GameObjectDVs));

            currentRect = AddPropertyFromList(currentRect, gameObjectsDvProperty);

            SerializedProperty vector3DvProperty = property.FindPropertyRelative(nameof(VariableFactory.Vector3DVs));

            currentRect = AddPropertyFromList(currentRect, vector3DvProperty);

            SerializedProperty customDataTypesDvProperty =
                property.FindPropertyRelative(nameof(VariableFactory.CustomDataTypeDVs));

            currentRect = AddPropertyFromList(currentRect, customDataTypesDvProperty);

            //Add Participant variables
            EditorGUI.LabelField(currentRect, "--------");
            currentRect.y += LineHeight;
            EditorGUI.LabelField(currentRect, "Participant Variables:", EditorStyles.boldLabel);
            currentRect.y += LineHeight;

            SerializedProperty intParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.IntParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, intParticipantProperty);

            SerializedProperty floatParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.FloatParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, floatParticipantProperty);

            SerializedProperty stringParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.StringParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, stringParticipantProperty);

            SerializedProperty boolParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.BoolParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, boolParticipantProperty);

            SerializedProperty gameObjectParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.GameObjectParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, gameObjectParticipantProperty);

            SerializedProperty vector3ParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.Vector3ParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, vector3ParticipantProperty);

            SerializedProperty customDataParticipantProperty =
                property.FindPropertyRelative(nameof(VariableFactory.CustomDataParticipantVariables));

            currentRect = AddPropertyFromList(currentRect, customDataParticipantProperty);



            EditorGUI.LabelField(currentRect, "--------");
            currentRect.y += LineHeight;

            EditorGUI.LabelField(currentRect, "Settings:", EditorStyles.boldLabel);
            currentRect.y += LineHeight;


            EditorGUI.indentLevel = oldIndentLevel;
            if (Math.Abs(height - currentRect.y) > 0.001f)
            {
                height = currentRect.y - oldY;
                //Debug.Log($"setting height of factory drawer to {height}");
            }

            property.serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 21
0
 public POP_Instruction(MonoLangParser.VarContext varContext)
 {
     _variable = VariableFactory.BuildVariable(varContext);
 }
Exemplo n.º 22
0
        private BasicBlock <Statement <TInstruction> > TransformBlock(BasicBlock <TInstruction> block)
        {
            int phiStatementCount = 0;
            var result            = new BasicBlock <Statement <TInstruction> >(block.Offset);

            var stackSlots               = _context.StackSlots;
            var phiSlots                 = _context.PhiSlots;
            var variableVersions         = _context.VariableVersions;
            var versionedAstVariables    = _context.VersionedAstVariables;
            var instructionVersionStates = _context.InstructionVersionStates;

            foreach (var instruction in block.Instructions)
            {
                long offset               = Architecture.GetOffset(instruction);
                var  dataFlowNode         = DataFlowGraph.Nodes[offset];
                var  stackDependencies    = dataFlowNode.StackDependencies;
                var  variableDependencies = dataFlowNode.VariableDependencies;
                var  targetVariables      = VariableFactory.CreateVariableBuffer(
                    stackDependencies.Count + variableDependencies.Count);

                for (int i = 0; i < stackDependencies.Count; i++)
                {
                    var sources = stackDependencies[i];
                    if (sources.Count == 1)
                    {
                        var source = sources.First();
                        targetVariables[i] = GetOrCreateStackSlot(source);
                    }
                    else
                    {
                        var phiVar = CreatePhiSlot();
                        var slots  = sources.Select(s =>
                                                    new VariableExpression <TInstruction>(GetOrCreateStackSlot(s)));
                        var phiStatement = new PhiStatement <TInstruction>(phiVar, slots.ToArray());

                        result.Instructions.Insert(phiStatementCount++, phiStatement);
                        targetVariables[i] = phiVar;
                    }
                }

                int index = stackDependencies.Count;
                foreach (var pair in variableDependencies)
                {
                    var variable   = pair.Key;
                    var dependency = pair.Value;
                    if (dependency.Count <= 1)
                    {
                        int version = _context.GetOrCreateVersion(variable);
                        var key     = (variable, version);

                        if (!versionedAstVariables.ContainsKey(key))
                        {
                            versionedAstVariables.Add(key, CreateVersionedVariable(variable));
                        }

                        targetVariables[index++] = versionedAstVariables[key];
                    }
                    else
                    {
                        var sources = AstVariableCollectionFactory <TInstruction> .CollectDependencies(
                            _context, variable, dependency);

                        if (phiSlots.TryGetValue(sources, out var phiSlot))
                        {
                            targetVariables[index++] = phiSlot;
                        }
                        else
                        {
                            phiSlot = CreatePhiSlot();
                            var phiStatement = new PhiStatement <TInstruction>(
                                phiSlot, sources.Select(s => new VariableExpression <TInstruction>(s)).ToArray());
                            result.Instructions.Insert(phiStatementCount++, phiStatement);
                            phiSlots[sources]        = phiSlot;
                            targetVariables[index++] = phiSlot;
                        }
                    }
                }

                var instructionExpression = new InstructionExpression <TInstruction>(instruction,
                                                                                     targetVariables
                                                                                     .Select(t => new VariableExpression <TInstruction>(t))
                                                                                     .ToArray()
                                                                                     );

                int writtenVariablesCount = Architecture.GetWrittenVariablesCount(instruction);
                var writtenVariables      = VariableFactory.CreateVariableBuffer(writtenVariablesCount);

                if (writtenVariables.Length > 0)
                {
                    Architecture.GetWrittenVariables(instruction, writtenVariables.AsSpan());
                }

                foreach (var writtenVariable in writtenVariables)
                {
                    if (!instructionVersionStates.TryGetValue(offset, out var dict))
                    {
                        int version = _context.IncrementVersion(writtenVariable);

                        dict = new Dictionary <IVariable, int>();
                        instructionVersionStates[offset] = dict;

                        versionedAstVariables[(writtenVariable, version)] = CreateVersionedVariable(writtenVariable);
Exemplo n.º 23
0
 public ASSIGN_Instruction(MonoLangParser.VarContext varContext, MonoLangParser.ExpressionContext[] expressionContext)
 {
     _variable   = VariableFactory.BuildVariable(varContext);
     _expression = ExpressionFactory.BuildExpression(expressionContext[0]);
 }
 internal GeometryFactory(MapInfoSession MISession, VariableFactory variableFactory)
 {
     this.misession       = MISession;
     this.variablefactory = variableFactory;
 }
Exemplo n.º 25
0
 public void Setup()
 {
     _factory = new VariableFactory();
 }
 public GeometryFactory(MapInfoSession MISession)
 {
     this.misession       = MISession;
     this.variablefactory = new VariableFactory(MISession);
 }
Exemplo n.º 27
0
 public READ_Instruction(MonoLangParser.PortContext portContext, MonoLangParser.VarContext varContext)
 {
     _portName = portContext.name().NAME().GetText();
     _variable = VariableFactory.BuildVariable(varContext);
 }