public static bool IsUnmanaged(this Type type)
        {
            while (type.IsPointer || type.IsArray)
            {
                type = type.GetElementType();
            }

            if (type.IsPrimitive || type.IsEnum || bag.Contains(type))
            {
                return(true);
            }

            if (type.IsValueType)
            {
                HashSet <Type> done = new HashSet <Type>();
                Stack <IForwardIterator <FieldInfo> > stack = new Stack <IForwardIterator <FieldInfo> >();

                IForwardIterator <FieldInfo> e1 = type.GetFields(flg).Begin();
loop:
                for (; e1.IsAlive; e1.Add())
                {
                    Type tmp = e1.Value.FieldType;
                    if (tmp.IsPointer)
                    {
                        continue;
                    }
                    else if (!tmp.IsValueType)
                    {
                        return(false);
                    }
                    else if (!tmp.IsPrimitive && done.Add(tmp))
                    {
                        stack.Push(e1);
                        e1.Add();

                        e1 = tmp.GetFields(flg).Begin();
                        goto loop;
                    }
                }

                if (stack.Count > 0)
                {
                    e1 = stack.Pop();
                    goto loop;
                }

                bag.Add(type);
                return(true);
            }

            return(false);
        }
Beispiel #2
0
        public static void Closure(CachedGrammar inst, LinkedHashSet <LRxItem> items)
        {
            Grammar g = inst.m_value;
            IForwardIterator <LRxItem> e1 = items.Begin();
            IForwardIterator <LRxItem> e2 = items.Begin();

            for (; e1.IsAlive; e1.Add())
            {
                LRxItem current = e1.Value;
                if (current.IsEnd)
                {
                    continue;
                }

                int ms = current.MarkSymbol;
                if (!ms.IsTerminal())
                {
                    CHashSet <int> la =
                        current.IsLast
                        ? new CHashSet <int>(current.lookahead)
                        : inst.GetFirst(current.express, current.index + 1);

                    IForwardIterator <GItem> e3 = g.Find(ms);
                    do
                    {
                        LRxItem newit = new LRxItem(e3.Value, la);

                        for (; e2.IsAlive; e2.Add())
                        {
                            if (newit.CoreEquals(e2.Value))
                            {
                                CHashSet <int> ela = e2.Value.lookahead;
                                if (!ela.IsSupersetOf(la))
                                {
                                    ela.UnionWith(la);
                                }

                                goto exit;
                            }
                        }

                        items.Add(newit);

exit:
                        e2.Reset();
                    } while (e3.LazyAdd());
                    e3.Dispose();
                }
            }

            e1.Dispose();
        }