public void AddTabPage(string key, int index)
 {
     string[] temp = key.Split(' ');
     if (temp[0] == "SERIES")
     {
         VariableTabPage seriesTabPage = new VariableTabPage();
         int             listIndex     = VariableFinder.FindVariableIndex(data.SeriesVariables, temp[1]);
         seriesTabPage.SetData(data.SeriesVariables[listIndex], data);
         seriesTabPage.ShowDataGrid();
         this.variableViewCollection.TabPages.Insert(index, seriesTabPage);
         this.variableViewCollection.SelectedIndex = this.variableViewCollection.TabPages.Count - 1;
     }
     else if (temp[0] == "GROUP")
     {
         GroupTabPage groupTabPage = new GroupTabPage();
         int          listIndex    = GroupFinder.FindGroupIndex(data.SeriesGroups, temp[1]);
         groupTabPage.SetData(data.SeriesGroups[listIndex], data);
         groupTabPage.ShowDataGrid();
         this.variableViewCollection.TabPages.Insert(index, groupTabPage);
         this.variableViewCollection.SelectedIndex = this.variableViewCollection.TabPages.Count - 1;
     }
     else if (temp[0] == "STOCK")
     {
         StockTabPage stockTabPage = new StockTabPage();
         int          listIndex    = StockFinder.FindStockIndex(data.SeriesStocks, temp[1]);
         stockTabPage.SetData(data.SeriesStocks[listIndex], data);
         stockTabPage.ShowDataGrid();
         this.variableViewCollection.TabPages.Insert(index, stockTabPage);
         this.variableViewCollection.SelectedIndex = this.variableViewCollection.TabPages.Count - 1;
     }
 }
        protected virtual bool CheckTheLoop(WhileStatement theWhile, VariableReference forVariable)
        {
            if (theWhile == null || theWhile.Body.Statements.Count < 2)
            {
                return(false);
            }

            VariableFinder variableFinder = new VariableFinder(forVariable);

            if (!variableFinder.FindVariable(theWhile.Condition))
            {
                return(false);
            }

            ExpressionStatement incrementCandidate = theWhile.Body.Statements[theWhile.Body.Statements.Count - 1] as ExpressionStatement;
            VariableReference   incrementVariable;

            if (incrementCandidate == null || !TryGetAssignedVariable(incrementCandidate, out incrementVariable) || forVariable != incrementVariable)
            {
                return(false);
            }

            ContinueFinder continueFinder = new ContinueFinder();

            return(!continueFinder.FindContinue(theWhile.Body));
        }
示例#3
0
            public static ICollection <char> Find(Expression e)
            {
                var finder = new VariableFinder();

                finder.Visit(e);
                return(finder.vars);
            }
示例#4
0
        private FileParser CreateSut()
        {
            var variableParser = new VariableFinder();
            var cmdBuilder     = new ParseCommandBuilder(variableParser);
            var executor       = new CommandExecutor(cmdBuilder);
            var tester         = new BlankCommandHandler();
            var instrBuilder   = new ParseInstructionBuilder(variableParser, executor, tester);

            return(new FileParser(instrBuilder));
        }
        public static Func <FastDictionary2 <TKey, TValue> > CreateFastDictionary2Generator <TKey, TValue>(
            this IEqualityComparerExpression <TKey> comparerExp, int capacity, Func <TKey, TKey, bool> equalsFunc, Func <TKey, int> getHashCodeFunc, QueryContainer container)
        {
            if (EqualityComparerExpression <TKey> .IsSimpleDefault(comparerExp))
            {
                return(() => new FastDictionary2 <TKey, TValue>());
            }
            if (container == null)
            {
                return(() => new FastDictionary2 <TKey, TValue>(capacity, equalsFunc, getHashCodeFunc));
            }

            var equalsExp      = comparerExp.GetEqualsExpr();
            var getHashCodeExp = comparerExp.GetGetHashCodeExpr();
            var vars           = VariableFinder.Find(equalsExp).Select(o => o.GetHashCode()).ToList();

            if (!vars.Any())
            {
                vars.Add(string.Empty.StableHash());
            }
            var hashvars = VariableFinder.Find(getHashCodeExp).Select(o => o.GetHashCode()).ToList();

            if (!hashvars.Any())
            {
                hashvars.Add(string.Empty.StableHash());
            }
            var key =
                Tuple.Create(
                    equalsExp.ToString() + getHashCodeExp.ToString() + string.Concat(vars.Aggregate((a, i) => a ^ i)) + string.Concat(hashvars.Aggregate((a, i) => a ^ i)),
                    typeof(TKey), typeof(TValue));

            Type temp;

            lock (sentinel)
            {
                if (!generatorCache.TryGetValue(key, out temp))
                {
                    string typeName    = Prefix + classCounter++;
                    var    builderCode = new GeneratedFastDictionary(typeName, "2").TransformText();
                    var    a           = Transformer.CompileSourceCode(builderCode, Array.Empty <Assembly>(), out string errorMessages);

                    temp = a.GetType(typeName + "`2");
                    temp = temp.MakeGenericType(typeof(TKey), typeof(TValue));
                    MethodInfo init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public);
                    init.Invoke(null, new object[] { equalsFunc, getHashCodeFunc, capacity });
                    generatorCache.Add(key, temp);
                }
                if (!container.TryGetFastDictionary2Type(key, out Type other))
                {
                    container.RegisterFastDictionary2Type(key, temp);
                }
            }

            return(() => (FastDictionary2 <TKey, TValue>)Activator.CreateInstance(temp));
        }
        public static IDictionary <string, string> Parse(Stream input)
        {
            var variableParser = new VariableFinder();
            var cmdBuilder     = new ParseCommandBuilder(variableParser);
            var executor       = new CommandExecutor(cmdBuilder);
            var tester         = new BlankCommandHandler();
            var instrBuilder   = new ParseInstructionBuilder(variableParser, executor, tester);
            var fileParser     = new FileParser(instrBuilder);
            var parser         = new TWConfigurationFileParser(fileParser);

            return(parser.ParseStream(input));
        }
示例#7
0
        public static Expression <Func <SortedDictionary <TKey, TValue> > > CreateSortedDictionaryGenerator <TKey, TValue>(this IComparerExpression <TKey> comparerExp, QueryContainer container)
        {
            if (ComparerExpression <TKey> .IsSimpleDefault(comparerExp))
            {
                return(() => new SortedDictionary <TKey, TValue>());
            }

            var expr = comparerExp.GetCompareExpr();

            if (container == null)
            {
                Expression <Func <Comparison <TKey>, SortedDictionary <TKey, TValue> > > template
                    = (c) => new SortedDictionary <TKey, TValue>(Comparer <TKey> .Create(c));
                var replaced = template.ReplaceParametersInBody(expr);
                return(Expression.Lambda <Func <SortedDictionary <TKey, TValue> > >(replaced));
            }

            var expression = expr.ToString();
            var vars       = VariableFinder.Find(expr).Select(o => o.GetHashCode());
            var captures   = vars.Aggregate(expression.GetHashCode(), (a, i) => a ^ i);
            var key        = Tuple.Create(expression + string.Concat(vars.Select(o => o.ToString(CultureInfo.InvariantCulture))), typeof(TKey), typeof(TValue));

            Type temp;

            lock (sentinel)
            {
                if (!DictionaryTypes.TryGetValue(key, out temp))
                {
                    string typeName = Prefix
                                      + captures.ToString(CultureInfo.InvariantCulture)
                                      + typeof(TKey).ToString().GetHashCode().ToString(CultureInfo.InvariantCulture)
                                      + typeof(TValue).ToString().GetHashCode().ToString(CultureInfo.InvariantCulture);
                    typeName = typeName.Replace("-", "_");
                    var builderCode        = new GeneratedSortedDictionary(typeName).TransformText();
                    var assemblyReferences = Transformer.AssemblyReferencesNeededFor(typeof(SortedDictionary <,>));
                    var a = Transformer.CompileSourceCode(builderCode, assemblyReferences, out string errorMessages);

                    temp = a.GetType(typeName + "`2");
                    temp = temp.MakeGenericType(typeof(TKey), typeof(TValue));
                    var init = temp.GetTypeInfo().GetMethod("Initialize", BindingFlags.Static | BindingFlags.Public);
                    init.Invoke(null, new object[] { Comparer <TKey> .Create(expr.Compile()) });
                    DictionaryTypes.Add(key, temp);
                }
                if (!container.TryGetSortedDictionaryType(key, out Type other))
                {
                    container.RegisterSortedDictionaryType(key, temp);
                }
            }
            return(Expression.Lambda <Func <SortedDictionary <TKey, TValue> > >(Expression.New(temp)));
        }
示例#8
0
        /// <summary>
        /// Check does some sanity check, e.g., if a variable is re-defined.
        /// </summary>
        /// <param name="asts"></param>
        private static List <WarningEntry> Check(IEnumerable <AssociativeNode> asts)
        {
            var warnings = new List <WarningEntry>();

            HashSet <string> scope = new HashSet <string>();

            foreach (var node in asts)
            {
                BinaryExpressionNode bnode = node as BinaryExpressionNode;
                if (bnode == null || bnode.Optr != Operator.assign)
                {
                    continue;
                }

                IdentifierNode ident = bnode.LeftNode as IdentifierNode;
                if (ident == null)
                {
                    continue;
                }

                var variable = ident.Value;

                if (!scope.Contains(variable))
                {
                    scope.Add(variable);

                    VariableFinder finder = new VariableFinder(variable);
                    bnode.RightNode.Accept(finder);

                    if (finder.Found)
                    {
                        warnings.Add(new WarningEntry
                        {
                            Message = String.Format(Resources.VariableRecursiveReference, variable),
                        });
                        node.skipMe = true;
                    }
                }
                else if (ident.ArrayDimensions == null)
                {
                    warnings.Add(new WarningEntry
                    {
                        Message = String.Format(Resources.VariableRedifinitionError, variable),
                    });
                    node.skipMe = true;
                }
            }

            return(warnings);
        }
示例#9
0
			private void FixExpression()
			{
				if (this.variableReference == null)
				{
					return;
				}
				V_0 = new VariableFinder(this.variableReference);
				V_1 = this.expression as BinaryExpression;
				if (V_1.get_Right().IsReferenceExpression() && !V_0.FindVariable(this.theTry.get_Try()))
				{
					V_2 = new List<Instruction>(V_1.get_Left().get_UnderlyingSameMethodInstructions());
					V_2.AddRange(V_1.get_MappedInstructions());
					this.expression = V_1.get_Right().CloneAndAttachInstructions(V_2);
				}
				return;
			}
示例#10
0
            private void FixExpression()
            {
                if (variableReference == null)
                {
                    return;
                }

                VariableFinder   finder           = new VariableFinder(this.variableReference);
                BinaryExpression assignExpression = this.expression as BinaryExpression;

                if (assignExpression.Right.IsReferenceExpression() && !finder.FindVariable(theTry.Try))
                {
                    List <Instruction> instructions = new List <Instruction>(assignExpression.Left.UnderlyingSameMethodInstructions);
                    instructions.AddRange(assignExpression.MappedInstructions);
                    this.expression = assignExpression.Right.CloneAndAttachInstructions(instructions);
                }
            }
示例#11
0
        /// <summary>
        /// Check does some sanity check, e.g., if a variable is re-defined.
        /// </summary>
        /// <param name="asts"></param>
        private static List <WarningEntry> Check(IEnumerable <AssociativeNode> asts)
        {
            var warnings = new List <WarningEntry>();

            HashSet <string> scope = new HashSet <string>();

            foreach (var node in asts)
            {
                BinaryExpressionNode bnode = node as BinaryExpressionNode;
                if (bnode == null || bnode.Optr != Operator.assign)
                {
                    var fNode = node as FunctionDefinitionNode;
                    if (fNode != null)
                    {
                        var fbody = NodeUtils.Clone(fNode.FunctionBody) as CodeBlockNode;
                        var body  = fbody.Body;

                        warnings.AddRange(Check(body));

                        fNode.FunctionBody.Body.Clear();
                        fNode.FunctionBody.Body.AddRange(body.Where(n => !n.skipMe));
                    }

                    continue;
                }

                IdentifierNode ident = bnode.LeftNode as IdentifierNode;
                if (ident == null)
                {
                    continue;
                }

                var variable = ident.Value;

                if (!scope.Contains(variable))
                {
                    scope.Add(variable);

                    VariableFinder finder = new VariableFinder(variable);

                    var langNode = bnode.RightNode as LanguageBlockNode;
                    if (langNode != null)
                    {
                        var cbn = langNode.CodeBlockNode as CodeBlockNode;
                        if (cbn != null)
                        {
                            var copy = NodeUtils.Clone(cbn) as CodeBlockNode;

                            warnings.AddRange(Check(copy.Body));

                            cbn.Body.Clear();
                            cbn.Body.AddRange(copy.Body.Where(n => !n.skipMe));
                        }
                        continue;
                    }
                    bnode.RightNode.Accept(finder);

                    if (finder.Found)
                    {
                        warnings.Add(new WarningEntry
                        {
                            Message = String.Format(Resources.VariableRecursiveReference, variable),
                        });
                        node.skipMe = true;
                    }
                }
                else if (ident.ArrayDimensions == null)
                {
                    warnings.Add(new WarningEntry
                    {
                        Message = String.Format(Resources.VariableRedifinitionError, variable),
                    });
                    node.skipMe = true;
                }
            }

            return(warnings);
        }