예제 #1
0
        private static IEnumerable <Token> ExpandAllIdentifiers(EAParser p, Queue <Token> tokens, ImmutableStack <string> seenDefs, ImmutableStack <Tuple <string, int> > seenMacros)
        {
            IEnumerable <Token> output = new List <Token>();

            while (tokens.Count > 0)
            {
                Token current = tokens.Dequeue();
                if (current.Type == TokenType.IDENTIFIER)
                {
                    if (p.Macros.ContainsName(current.Content) && tokens.Count > 0 && tokens.Peek().Type == TokenType.OPEN_PAREN)
                    {
                        IList <IList <Token> > param = p.ParseMacroParamList(new MergeableGenerator <Token>(tokens)); //TODO: I don't like wrapping this in a mergeable generator..... Maybe interface the original better?
                        if (!seenMacros.Contains(new Tuple <string, int>(current.Content, param.Count)) && p.Macros.HasMacro(current.Content, param.Count))
                        {
                            foreach (Token t in  p.Macros.GetMacro(current.Content, param.Count).ApplyMacro(current, param, p.GlobalScope))
                            {
                                yield return(t);
                            }
                        }
                        else if (seenMacros.Contains(new Tuple <string, int>(current.Content, param.Count)))
                        {
                            yield return(current);

                            foreach (IList <Token> l in param)
                            {
                                foreach (Token t in l)
                                {
                                    yield return(t);
                                }
                            }
                        }
                        else
                        {
                            yield return(current);
                        }
                    }
                    else if (!seenDefs.Contains(current.Content) && p.Definitions.ContainsKey(current.Content))
                    {
                        foreach (Token t in p.Definitions[current.Content].ApplyDefinition(current))
                        {
                            yield return(t);
                        }
                    }
                    else
                    {
                        yield return(current);
                    }
                }
                else
                {
                    yield return(current);
                }
            }
        }
예제 #2
0
        protected internal override Expression VisitEntity(EntityExpression ee)
        {
            if (previousTypes.Contains(ee.Type) || IsCached(ee.Type) || ee.AvoidExpandOnRetrieving)
            {
                ee = new EntityExpression(ee.Type, ee.ExternalId, null, null, null, null, null /*ee.SystemPeriod TODO*/, ee.AvoidExpandOnRetrieving);
            }
            else
            {
                ee = binder.Completed(ee);
            }

            previousTypes = previousTypes.Push(ee.Type);

            var bindings = VisitBindings(ee.Bindings !);

            var mixins = Visit(ee.Mixins, VisitMixinEntity);

            var id = (PrimaryKeyExpression)Visit(ee.ExternalId);

            var result = new EntityExpression(ee.Type, id, ee.ExternalPeriod, ee.TableAlias, bindings, mixins, ee.TablePeriod, ee.AvoidExpandOnRetrieving);

            previousTypes = previousTypes.Pop();

            return(result);
        }
예제 #3
0
        /// <summary>
        /// Checks if the input file results in a circular reference.
        /// </summary>
        public static bool IsCircularReference(object file, out IEnumerable <object> dependencyChain)
        {
            dependencyChain = null;

            if (t_files.Contains(file))
            {
                dependencyChain = t_files.Reverse();
                return(true);
            }

            return(false);
        }
예제 #4
0
        private static void AddEmbeddedInterfaces(Type type, HashSet <Type> relevantEmbeddedTypes, ImmutableStack <Type> observedTypes = null)
        {
            Requires.NotNull(type, nameof(type));
            Requires.NotNull(relevantEmbeddedTypes, nameof(relevantEmbeddedTypes));

            observedTypes = observedTypes ?? ImmutableStack <Type> .Empty;
            if (observedTypes.Contains(type))
            {
                // avoid stackoverflow (when T implements IComparable<T>, for example).
                return;
            }

            observedTypes = observedTypes.Push(type);
            if (type.GetTypeInfo().Assembly != Mscorlib)
            {
                if (type.IsEmbeddedType())
                {
                    relevantEmbeddedTypes.Add(type);
                }

                if (type.GetTypeInfo().BaseType != null)
                {
                    AddEmbeddedInterfaces(type.GetTypeInfo().BaseType, relevantEmbeddedTypes, observedTypes);
                }

                foreach (Type iface in type.GetTypeInfo().ImplementedInterfaces)
                {
                    AddEmbeddedInterfaces(iface, relevantEmbeddedTypes, observedTypes);
                }
            }

            if (type.GetTypeInfo().IsGenericType)
            {
                foreach (Type typeArg in type.GenericTypeArguments)
                {
                    AddEmbeddedInterfaces(typeArg, relevantEmbeddedTypes, observedTypes);
                }
            }
        }
예제 #5
0
        private void FindAllPaths(List <ImmutableStack <ExecutionBlock> > paths, ImmutableStack <ExecutionBlock> currentPath, ExecutionBlock sourceBlock, ExecutionBlock targetBlock)
        {
            List <ExecutionBlock> nextBlocks;

            if (!executionOutputs.TryGetValue(sourceBlock, out nextBlocks))
            {
                return;
            }

            foreach (var nextBlock in nextBlocks)
            {
                if (nextBlock == targetBlock)
                {
                    // We've reached our target, record this path
                    paths.Add(currentPath);
                }
                else if (!currentPath.Contains(nextBlock)) // avoid cycles
                {
                    // Recurse
                    FindAllPaths(paths, currentPath.Push(nextBlock), nextBlock, targetBlock);
                }
            }
        }
        public bool AddMigration(Migration migration)
        {
            if (_working.Contains(migration))
            {
                return(false);
            }

            foreach (var prerequisite in migration.AllPrerequisites
                     .Where(p => _difference.Contains(p)))
            {
                if (!AddMigration(prerequisite))
                {
                    return(false);
                }
            }

            _working = _working.Push(migration);

            var migrationsAffected = new MigrationHistoryBuilder();

            migrationsAffected.Append(migration);
            string[] result = migration.GenerateSql(migrationsAffected, this);
            _sql = _sql.AddRange(result);
            var mementos = migrationsAffected.MigrationHistory.GetMementos().ToList();

            _sql = _sql.Add(GenerateInsertStatement(_databaseName, mementos));
            if (mementos.SelectMany(m => m.Prerequisites).SelectMany(p => p.Value).Any())
            {
                _sql = _sql.Add(GeneratePrerequisiteInsertStatements(_databaseName, mementos));
            }
            _difference = _difference.Subtract(migrationsAffected.MigrationHistory);

            _working = _working.Pop();

            return(true);
        }
예제 #7
0
 public static bool Contains <TSource>(this ImmutableStack <TSource> source, TSource value)
 => source.Contains(value);