get() public method

public get ( int i ) : object
i int
return object
Beispiel #1
0
        public override long compare(object obj)
        {
            Version that = (Version)obj;
            List    a    = this.m_segments;
            List    b    = that.m_segments;

            for (int i = 0; i < a.sz() && i < b.sz(); i++)
            {
                long ai = (a.get(i) as Long).longValue();
                long bi = (b.get(i) as Long).longValue();
                if (ai < bi)
                {
                    return(-1);
                }
                if (ai > bi)
                {
                    return(+1);
                }
            }
            if (a.sz() < b.sz())
            {
                return(-1);
            }
            if (a.sz() > b.sz())
            {
                return(+1);
            }
            return(0);
        }
Beispiel #2
0
        public List removeAll(List toRemove)
        {
            // optimize special cases
            modify();
            if (toRemove.sz() == 0)
            {
                return(this);
            }
            if (toRemove.sz() == 1)
            {
                remove(toRemove.get(0)); return(this);
            }

            // rebuild the backing store array, implementation
            // assumes that this list is bigger than toRemove list
            object[] newValues = new object[m_values.Length];
            int      newSize   = 0;

            for (int i = 0; i < m_size; ++i)
            {
                object val = m_values[i];
                if (!toRemove.contains(val))
                {
                    newValues[newSize++] = val;
                }
            }
            this.m_values = newValues;
            this.m_size   = newSize;
            return(this);
        }
Beispiel #3
0
        protected void doReflect()
        {
            // ensure master type is reflected
            Type master = m_base;

            master.finish();
            List masterSlots = master.slots();

            // allocate slot data structures
            m_fields      = new List(Sys.FieldType, master.fields().sz());
            m_methods     = new List(Sys.MethodType, master.methods().sz());
            m_slots       = new List(Sys.SlotType, masterSlots.sz());
            m_slotsByName = new Hashtable(masterSlots.sz() * 3);

            // parameterize master's slots
            for (int i = 0; i < masterSlots.sz(); i++)
            {
                Slot slot = (Slot)masterSlots.get(i);
                if (slot is Method)
                {
                    slot = parameterize((Method)slot);
                    m_methods.add(slot);
                }
                else
                {
                    slot = parameterize((Field)slot);
                    m_fields.add(slot);
                }
                m_slots.add(slot);
                m_slotsByName[slot.m_name] = slot;
            }
        }
Beispiel #4
0
        public override void delete()
        {
            if (!exists())
            {
                return;
            }

            if (m_file is DirectoryInfo)
            {
                List kids = list();
                for (int i = 0; i < kids.sz(); i++)
                {
                    (kids.get(i) as File).delete();
                }
            }

            try
            {
                m_file.Delete();
                m_file.Refresh();
            }
            catch (System.Exception e)
            {
                throw IOErr.make("Cannot delete: " + m_file, e).val;
            }
        }
Beispiel #5
0
        public override List inheritance()
        {
            if (m_inheritance == null)
            {
                Hashtable map = new Hashtable();
                List      acc = new List(Sys.TypeType);

                // handle Void as a special case
                if (this == Sys.VoidType)
                {
                    acc.add(this);
                    return(m_inheritance = acc.trim());
                }

                // add myself
                map[m_qname] = this;
                acc.add(this);

                // add my direct inheritance inheritance
                addInheritance(@base(), acc, map);
                List m = mixins();
                for (int i = 0; i < m.sz(); i++)
                {
                    addInheritance((Type)m.get(i), acc, map);
                }

                m_inheritance = acc.trim().ro();
            }
            return(m_inheritance);
        }
Beispiel #6
0
 public static List list()
 {
     lock (m_podsByName)
     {
         // TODO - eventually we need a faster way to load
         //  pod meta-data into memory without actually loading
         //  every pod into memory
         if (m_allPodsList == null)
         {
             List names = Env.cur().findAllPodNames();
             List pods  = new List(Sys.PodType);
             for (int i = 0; i < names.sz(); ++i)
             {
                 string name = (string)names.get(i);
                 try
                 {
                     pods.add(doFind(name, true, null));
                 }
                 catch (Exception e)
                 {
                     System.Console.WriteLine("ERROR: Invalid pod file: " + name);
                     Err.dumpStack(e);
                 }
             }
             m_allPodsList = pods.ro();
         }
         return(m_allPodsList);
     }
 }
Beispiel #7
0
        private static object doTrap(object self, string name, List args, Type type)
        {
            Slot slot = type.slot(name, true);

            if (slot is Method)
            {
                Method m = (Method)slot;
                return(m.m_func.callOn(self, args));
            }
            else
            {
                Field f       = (Field)slot;
                int   argSize = (args == null) ? 0 : args.sz();
                if (argSize == 0)
                {
                    return(FanUtil.box(f.get(self)));
                }

                if (argSize == 1)
                {
                    object val = args.get(0);
                    f.set(self, val);
                    return(FanUtil.box(val));
                }

                throw ArgErr.make("Invalid number of args to get or set field '" + name + "'").val;
            }
        }
Beispiel #8
0
        public virtual object make(List args)
        {
            Method make = method("make", false);

            if (make != null && make.isPublic())
            {
                int  numArgs = args == null ? 0 : args.sz();
                List p       = make.@params();
                if ((numArgs == p.sz()) ||
                    (numArgs < p.sz() && ((Param)p.get(numArgs)).hasDefault()))
                {
                    return(make.m_func.callList(args));
                }
            }

            Slot defVal = slot("defVal", false);

            if (defVal is Field)
            {
                return(((Field)defVal).get(null));
            }
            if (defVal is Method)
            {
                return(((Method)defVal).m_func.callList(null));
            }

            throw Err.make("Type missing 'make' or 'defVal' slots: " + this).val;
        }
Beispiel #9
0
        public virtual OutStream writeProps(Map props, bool cls)
        {
            Charset origCharset = charset();

            charset(Charset.utf8());
            try
            {
                List keys = props.keys().sort();
                int  size = keys.sz();
                long eq   = '=';
                long nl   = '\n';
                for (int i = 0; i < size; ++i)
                {
                    string key = (string)keys.get(i);
                    string val = (string)props.get(key);
                    writePropStr(key);
                    writeChar(eq);
                    writePropStr(val);
                    writeChar(nl);
                }
                return(this);
            }
            finally
            {
                try { if (cls)
                      {
                          close();
                      }
                } catch (System.Exception e) { Err.dumpStack(e); }
                charset(origCharset);
            }
        }
Beispiel #10
0
            public override object callList(List args)
            {
                int argsSize = args == null ? 0 : args.sz();

                bool isStatic = _isStatic();
                int  p        = checkArgs(argsSize, isStatic, false);

                object[] a = new object[p];

                if (isStatic)
                {
                    if (args != null && a.Length > 0)
                    {
                        args.toArray(a, 0, a.Length);
                    }
                    return(m.invoke(null, a));
                }
                else
                {
                    object i = args.get(0);
                    if (a.Length > 0)
                    {
                        args.toArray(a, 1, a.Length);
                    }
                    return(m.invoke(i, a));
                }
            }
Beispiel #11
0
 public bool containsAny(List list)
 {
     for (int i = 0; i < list.sz(); i++)
     {
         if (index(list.get(i)) != null)
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #12
0
 static Map read(Map defProps, Key key, List files)
 {
     if (files.isEmpty()) return defProps;
       Map acc = defProps.dup();
       for (int i=files.sz()-1; i>=0; --i)
       {
     InStream input = ((File)files.get(i)).@in();
     try { acc.setAll(input.readProps()); }
     finally { input.close(); }
       }
       return (Map)acc.toImmutable();
 }
Beispiel #13
0
 static List checkIds(List ids)
 {
     if (ids.sz() == 0)
     {
         throw ParseErr.make("No unit ids defined").val;
     }
     for (int i = 0; i < ids.sz(); ++i)
     {
         checkId((string)ids.get(i));
     }
     return((List)ids.toImmutable());
 }
Beispiel #14
0
 public Map addList(List list, Func f)
 {
     modify();
     if (f == null)
     {
         for (int i = 0; i < list.sz(); ++i)
         {
             add(list.get(i), list.get(i));
         }
     }
     else if (f.@params().sz() == 1)
     {
         for (int i = 0; i < list.sz(); ++i)
         {
             add(f.call(list.get(i)), list.get(i));
         }
     }
     else
     {
         for (int i = 0; i < list.sz(); ++i)
         {
             add(f.call(list.get(i), i), list.get(i));
         }
     }
     return(this);
 }
Beispiel #15
0
        /// <summary>
        /// Merge the inherit's slots into my slot maps.
        ///   slots:       Slot[] by order
        ///   nameToSlot:  String name -> Slot
        ///   nameToIndex: String name -> Long index of slots
        /// </summary>
        private void merge(Type inheritedType, List slots, Hashtable nameToSlot, Hashtable nameToIndex)
        {
            if (inheritedType == null)
            {
                return;
            }
            List inheritedSlots = inheritedType.reflect().slots();

            for (int i = 0; i < inheritedSlots.sz(); ++i)
            {
                merge((Slot)inheritedSlots.get(i), slots, nameToSlot, nameToIndex);
            }
        }
Beispiel #16
0
        //////////////////////////////////////////////////////////////////////////
        // Construction
        //////////////////////////////////////////////////////////////////////////

        public static string fromChars(List chars)
        {
            if (chars.sz() == 0)
            {
                return("");
            }
            StringBuilder s = new StringBuilder(chars.sz());

            for (int i = 0; i < chars.sz(); ++i)
            {
                s.Append((char)((Long)chars.get(i)).longValue());
            }
            return(s.ToString());
        }
Beispiel #17
0
        /**
         * Parse an dimension string and intern it:
         *   dim    := <ratio> ["*" <ratio>]*
         *   ratio  := <base> <exp>
         *   base   := "kg" | "m" | "sec" | "K" | "A" | "mol" | "cd"
         */
        private static Dimension parseDim(string s)
        {
            // handle empty string as dimensionless
            if (s.Length == 0)
            {
                return(m_dimensionless);
            }

            // parse dimension
            Dimension dim    = new Dimension();
            List      ratios = FanStr.split(s, Long.valueOf((long)'*'), true);

            for (int i = 0; i < ratios.sz(); ++i)
            {
                string r = (string)ratios.get(i);
                if (r.StartsWith("kg"))
                {
                    dim.kg = SByte.Parse(r.Substring(2).Trim()); continue;
                }
                if (r.StartsWith("sec"))
                {
                    dim.sec = SByte.Parse(r.Substring(3).Trim()); continue;
                }
                if (r.StartsWith("mol"))
                {
                    dim.mol = SByte.Parse(r.Substring(3).Trim()); continue;
                }
                if (r.StartsWith("m"))
                {
                    dim.m = SByte.Parse(r.Substring(1).Trim()); continue;
                }
                if (r.StartsWith("K"))
                {
                    dim.K = SByte.Parse(r.Substring(1).Trim()); continue;
                }
                if (r.StartsWith("A"))
                {
                    dim.A = SByte.Parse(r.Substring(1).Trim()); continue;
                }
                if (r.StartsWith("cd"))
                {
                    dim.cd = SByte.Parse(r.Substring(2).Trim()); continue;
                }
                throw new Exception("Bad ratio '" + r + "'");
            }

            // intern
            return(dim.intern());
        }
Beispiel #18
0
        public virtual List findAllPodNames()
        {
            List acc   = new List(Sys.StrType);
            List files = findFile(Uri.fromStr("lib/fan/")).list();

            for (int i = 0; i < files.sz(); ++i)
            {
                File f = (File)files.get(i);
                if (f.isDir() || "pod" != f.ext())
                {
                    continue;
                }
                acc.add(f.basename());
            }
            return(acc);
        }
Beispiel #19
0
        //////////////////////////////////////////////////////////////////////////
        // Lifecycle
        //////////////////////////////////////////////////////////////////////////

        public static Service install(Service self)
        {
            try
            {
                List types = FanObj.@typeof(self).inheritance();
                lock (m_lock)
                {
                    // if already installed, short circuit
                    if (self.isInstalled())
                    {
                        return(self);
                    }

                    // add to byService map
                    byService[self] = new State(self);

                    // add to map for each type service implements
                    for (int i = 0; i < types.sz(); ++i)
                    {
                        Type t = (Type)types.get(i);
                        if (!isServiceType(t))
                        {
                            continue;
                        }
                        Node node = new Node(self);
                        Node x    = (Node)byType[t.qname()];
                        if (x == null)
                        {
                            byType[t.qname()] = node;
                        }
                        else
                        {
                            while (x.next != null)
                            {
                                x = x.next;
                            }
                            x.next = node;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Err.dumpStack(e);
            }
            return(self);
        }
Beispiel #20
0
        public static Version make(List segments)
        {
            bool valid = segments.sz() > 0;

            for (int i = 0; i < segments.sz(); i++)
            {
                if (((Long)segments.get(i)).longValue() < 0)
                {
                    valid = false;
                }
            }
            if (!valid)
            {
                throw ArgErr.make("Invalid Version: '" + segments + "'").val;
            }
            return(new Version(segments));
        }
Beispiel #21
0
        private void addInheritance(Type t, List acc, Hashtable map)
        {
            if (t == null)
            {
                return;
            }
            List ti = t.inheritance();

            for (int i = 0; i < ti.sz(); i++)
            {
                Type x = (Type)ti.get(i);
                if (map[x.qname()] == null)
                {
                    map[x.qname()] = x;
                    acc.add(x);
                }
            }
        }
Beispiel #22
0
        /// <summary>
        /// Compute if the method signature contains generic parameter types.
        /// </summary>
        private static int toMask(Type parent, Type returns, List pars)
        {
            // we only use generics in Sys
            if (parent.pod() != Sys.m_sysPod)
            {
                return(0);
            }

            int p = returns.isGenericParameter() ? 1 : 0;

            for (int i = 0; i < pars.sz(); ++i)
            {
                p |= ((Param)pars.get(i)).m_type.isGenericParameter() ? 1 : 0;
            }

            int mask = 0;

            if (p != 0)
            {
                mask |= GENERIC;
            }
            return(mask);
        }
Beispiel #23
0
        public override bool @is(Type type)
        {
            // we don't take nullable into account for fits
            if (type is NullableType)
            {
                type = ((NullableType)type).m_root;
            }

            if (type == this || (type == Sys.ObjType && this != Sys.VoidType))
            {
                return(true);
            }
            List inherit = inheritance();

            for (int i = 0; i < inherit.sz(); ++i)
            {
                if (inherit.get(i) == type)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #24
0
Datei: Uri.cs Projekt: xored/f4
 static string toPathStr(bool isAbs, List path, bool isDir)
 {
     StringBuilder buf = new StringBuilder();
       if (isAbs) buf.Append('/');
       for (int i=0; i<path.sz(); ++i)
       {
     if (i > 0) buf.Append('/');
     buf.Append(path.get(i));
       }
       if (isDir && !(buf.Length > 0 && buf[buf.Length-1] == '/'))
     buf.Append('/');
       return buf.ToString();
 }
Beispiel #25
0
        /// <summary>
        /// Merge the inherited slot into my slot maps.  Assume this slot
        /// trumps any previous definition (because we process inheritance
        /// and my slots in the right order)
        ///   slots:       Slot[] by order
        ///   nameToSlot:  String name -> Slot
        ///   nameToIndex: String name -> Long index of slots
        /// </summary>
        private void merge(Slot slot, List slots, Hashtable nameToSlot, Hashtable nameToIndex)
        {
            // skip constructors which aren't mine
              if (slot.isCtor() && slot.m_parent != this) return;

              string name = slot.m_name;
              if (nameToIndex[name] != null)
              {
            int dup = (int)nameToIndex[name];

            // if the slot is inherited from Obj, then we can
            // safely ignore it as an override - the dup is most
            // likely already the same Obj method inherited from
            // a mixin; but the dup might actually be a more specific
            // override in which case we definitely don't want to
            // override with the sys::Obj version
            if (slot.parent() == Sys.ObjType)
              return;

            // if given the choice between two *inherited* slots where
            // one is concrete and abstract, then choose the concrete one
            Slot dupSlot = (Slot)slots.get(dup);
            if (slot.parent() != this && slot.isAbstract() && !dupSlot.isAbstract())
              return;

            // check if this is a Getter or Setter, in which case the Field
            // trumps and we need to cache the method on the Field
            // Note: this works because we assume the compiler always generates
            // the field before the getter and setter in fcode
            if ((slot.m_flags & (FConst.Getter|FConst.Setter)) != 0)
            {
              Field field = (Field)slots.get(dup);
              if ((slot.m_flags & FConst.Getter) != 0)
            field.m_getter = (Method)slot;
              else
            field.m_setter = (Method)slot;
              return;
            }

            nameToSlot[name] = slot;
            slots.set(dup, slot);
              }
              else
              {
            nameToSlot[name] = slot;
            slots.add(slot);
            nameToIndex[name] = slots.sz()-1;
              }
        }
Beispiel #26
0
        private void doReflect()
        {
            // if the ftype is non-null, that means it was passed in non-hollow
              // ftype (in-memory compile), otherwise we need to read it from the pod
              if (m_ftype.m_hollow)
              {
            try
            {
              m_ftype.read();
            }
            catch (IOException e)
            {
              Err.dumpStack(e);
              throw IOErr.make("Cannot read " + m_qname + " from pod", e).val;
            }
              }

              // these are working accumulators used to build the
              // data structures of my defined and inherited slots
              List slots  = new List(Sys.SlotType, 64);
              Hashtable nameToSlot  = new Hashtable();   // String -> Slot
              Hashtable nameToIndex = new Hashtable();   // String -> Long

              // merge in base class and mixin classes
              for (int i=0; i<m_mixins.sz(); i++) merge((Type)m_mixins.get(i), slots, nameToSlot, nameToIndex);
              merge(m_base, slots, nameToSlot, nameToIndex);

              // merge in all my slots
              FPod fpod   = this.m_pod.fpod;
              FType ftype = this.m_ftype;
              for (int i=0; i<ftype.m_fields.Length; i++)
              {
            Field f = map(fpod, ftype.m_fields[i]);
            merge(f, slots, nameToSlot, nameToIndex);
              }
              for (int i=0; i<ftype.m_methods.Length; i++)
              {
            Method m = map(fpod, ftype.m_methods[i]);
            merge(m, slots, nameToSlot, nameToIndex);
              }

              // break out into fields and methods
              List fields  = new List(Sys.FieldType,  slots.sz());
              List methods = new List(Sys.MethodType, slots.sz());
              for (int i=0; i<slots.sz(); i++)
              {
            Slot slot = (Slot)slots.get(i);
            if (slot is Field)
              fields.add(slot);
            else
              methods.add(slot);
              }
              this.m_slots       = slots.trim();
              this.m_fields      = fields.trim();
              this.m_methods     = methods.trim();
              this.m_slotsByName = nameToSlot;
              this.m_facets      = Facets.mapFacets(m_pod, ftype.m_attrs.m_facets);

              // facets
              this.m_lineNum    = m_ftype.m_attrs.m_lineNum;
              this.m_sourceFile = m_ftype.m_attrs.m_sourceFile;
        }
Beispiel #27
0
        public static Service uninstall(Service self)
        {
            try
            {
                List types = FanObj.@typeof(self).inheritance();
                lock (m_lock)
                {
                    // ensure service is stopped
                    stop(self);

                    // remove from byService map, it not installed short circuit
                    if (byService[self] == null)
                    {
                        return(self);
                    }
                    byService.Remove(self);

                    // remove from map for each type implemented by service
                    for (int i = 0; i < types.sz(); ++i)
                    {
                        // get next type in inheritance and check if service type
                        Type t = (Type)types.get(i);
                        if (!isServiceType(t))
                        {
                            continue;
                        }

                        // lookup linked list for that type
                        Node node = (Node)byType[t.qname()];
                        if (node == null)
                        {
                            continue;
                        }

                        // find this thread in the linked list
                        Node last = null;
                        bool cont = false;
                        while (node.service != self)
                        {
                            last = node;
                            node = node.next;
                            if (node == null)
                            {
                                cont = true; break;
                            }
                        }
                        if (cont)
                        {
                            continue;
                        }

                        // update the map or linked list
                        if (last == null)
                        {
                            byType[t.qname()] = node.next;
                        }
                        else
                        {
                            last.next = node.next;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Err.dumpStack(e);
            }
            return(self);
        }
Beispiel #28
0
        //////////////////////////////////////////////////////////////////////////
        // Complex
        //////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// complex := type [fields]
        /// fields  := "{" field (eos field)* "}"
        /// field   := name "=" obj
        /// </summary>
        private object readComplex(int line, Type t, bool root)
        {
            Map toSet = new Map(Sys.FieldType, Sys.ObjType.toNullable());
              List toAdd = new List(Sys.ObjType.toNullable());

              // read fields/collection into toSet/toAdd
              readComplexFields(t, toSet, toAdd);

              // get the make constructor
              Method makeCtor = t.method("make", false);
              if (makeCtor == null || !makeCtor.isPublic())
            throw err("Missing public constructor " + t.qname() + ".make", line);

              // get argument lists
              List args = null;
              if (root && options != null)
            args = (List)options.get("makeArgs");

              // construct object
              object obj = null;
              bool setAfterCtor = true;
              try
              {
            // if first parameter is an function then pass toSet
            // as an it-block for setting the fields
            Param p = (Param)makeCtor.@params().first();
            if (args == null && p != null && p.type().fits(Sys.FuncType))
            {
              args = new List(Sys.ObjType).add(Field.makeSetFunc(toSet));
              setAfterCtor = false;
            }

            // invoke make to construct object
            obj = makeCtor.callList(args);
              }
              catch (System.Exception e)
              {
            throw err("Cannot make " + t + ": " + e, line, e);
              }

              // set fields (if not passed to ctor as it-block)
              if (setAfterCtor && toSet.size() > 0)
              {
            IDictionaryEnumerator en = toSet.pairsIterator();
            while (en.MoveNext())
            {
              complexSet(obj, (Field)en.Key, en.Value, line);
            }
              }

              // add
              if (toAdd.size() > 0)
              {
            Method addMethod = t.method("add", false);
            if (addMethod == null) throw err("Method not found: " + t.qname() + ".add", line);
            for (int i=0; i<toAdd.sz(); ++i)
              complexAdd(t, obj, addMethod, toAdd.get(i), line);
              }

              return obj;
        }
Beispiel #29
0
        /// <summary>
        /// Merge the inherited slot into my slot maps.  Assume this slot
        /// trumps any previous definition (because we process inheritance
        /// and my slots in the right order)
        ///   slots:       Slot[] by order
        ///   nameToSlot:  String name -> Slot
        ///   nameToIndex: String name -> Long index of slots
        /// </summary>
        private void merge(Slot slot, List slots, Hashtable nameToSlot, Hashtable nameToIndex)
        {
            // skip constructors which aren't mine
            if (slot.isCtor() && slot.m_parent != this)
            {
                return;
            }

            string name = slot.m_name;

            if (nameToIndex[name] != null)
            {
                int dup = (int)nameToIndex[name];

                // if the slot is inherited from Obj, then we can
                // safely ignore it as an override - the dup is most
                // likely already the same Obj method inherited from
                // a mixin; but the dup might actually be a more specific
                // override in which case we definitely don't want to
                // override with the sys::Obj version
                if (slot.parent() == Sys.ObjType)
                {
                    return;
                }

                // if given the choice between two *inherited* slots where
                // one is concrete and abstract, then choose the concrete one
                Slot dupSlot = (Slot)slots.get(dup);
                if (slot.parent() != this && slot.isAbstract() && !dupSlot.isAbstract())
                {
                    return;
                }

                // check if this is a Getter or Setter, in which case the Field
                // trumps and we need to cache the method on the Field
                // Note: this works because we assume the compiler always generates
                // the field before the getter and setter in fcode
                if ((slot.m_flags & (FConst.Getter | FConst.Setter)) != 0)
                {
                    Field field = (Field)slots.get(dup);
                    if ((slot.m_flags & FConst.Getter) != 0)
                    {
                        field.m_getter = (Method)slot;
                    }
                    else
                    {
                        field.m_setter = (Method)slot;
                    }
                    return;
                }

                nameToSlot[name] = slot;
                slots.set(dup, slot);
            }
            else
            {
                nameToSlot[name] = slot;
                slots.add(slot);
                nameToIndex[name] = slots.sz() - 1;
            }
        }
Beispiel #30
0
        //////////////////////////////////////////////////////////////////////////
        // List
        //////////////////////////////////////////////////////////////////////////
        public void writeList(List list)
        {
            // get of type
              Type of = list.of();

              // decide if we're going output as single or multi-line format
              bool nl = isMultiLine(of);

              // figure out if we can use an inferred type
              bool inferred = false;
              if (curFieldType != null && curFieldType.fits(Sys.ListType))
              {
            inferred = true;
              }

              // clear field type, so it doesn't get used for inference again
              curFieldType = null;

              // if we don't have an inferred type, then prefix of type
              if (!inferred) wType(of);

              // handle empty list
              int size = list.sz();
              if (size == 0) { w("[,]"); return; }

              // items
              if (nl) w('\n').wIndent();
              w('[');
              level++;
              for (int i=0; i<size; ++i)
              {
            if (i > 0) w(',');
             if (nl) w('\n').wIndent();
            writeObj(list.get(i));
              }
              level--;
              if (nl) w('\n').wIndent();
              w(']');
        }
Beispiel #31
0
 public bool isStale(List x)
 {
     if (m_files.sz() != x.sz()) return true;
     for (int i=0; i<x.sz(); ++i)
       if (m_modified[i] != ((File)x.get(i)).modified().ticks())
     return true;
     return false;
 }
Beispiel #32
0
Datei: List.cs Projekt: xored/f4
        public List removeAll(List toRemove)
        {
            // optimize special cases
              modify();
              if (toRemove.sz() == 0) { return this; }
              if (toRemove.sz() == 1) { remove(toRemove.get(0)); return this; }

              // rebuild the backing store array, implementation
              // assumes that this list is bigger than toRemove list
              object[] newValues = new object[m_values.Length];
              int newSize = 0;
              for (int i=0; i<m_size; ++i)
              {
            object val = m_values[i];
            if (!toRemove.contains(val)) newValues[newSize++] = val;
              }
              this.m_values = newValues;
              this.m_size = newSize;
              return this;
        }
Beispiel #33
0
 private void loadFiles()
 {
     lock (m_filesMap)
       {
     if (m_filesList != null) return;
     this.m_filesList = (List)fpod.m_store.podFiles(uri()).toImmutable();
     for (int i=0; i<m_filesList.sz(); ++i)
     {
       Fan.Sys.File f = (Fan.Sys.File)m_filesList.get(i);
       m_filesMap[f.uri()] = f;
     }
       }
 }
Beispiel #34
0
        private void doReflect()
        {
            // if the ftype is non-null, that means it was passed in non-hollow
            // ftype (in-memory compile), otherwise we need to read it from the pod
            if (m_ftype.m_hollow)
            {
                try
                {
                    m_ftype.read();
                }
                catch (IOException e)
                {
                    Err.dumpStack(e);
                    throw IOErr.make("Cannot read " + m_qname + " from pod", e).val;
                }
            }

            // these are working accumulators used to build the
            // data structures of my defined and inherited slots
            List      slots       = new List(Sys.SlotType, 64);
            Hashtable nameToSlot  = new Hashtable(); // String -> Slot
            Hashtable nameToIndex = new Hashtable(); // String -> Long

            // merge in base class and mixin classes
            for (int i = 0; i < m_mixins.sz(); i++)
            {
                merge((Type)m_mixins.get(i), slots, nameToSlot, nameToIndex);
            }
            merge(m_base, slots, nameToSlot, nameToIndex);

            // merge in all my slots
            FPod  fpod  = this.m_pod.fpod;
            FType ftype = this.m_ftype;

            for (int i = 0; i < ftype.m_fields.Length; i++)
            {
                Field f = map(fpod, ftype.m_fields[i]);
                merge(f, slots, nameToSlot, nameToIndex);
            }
            for (int i = 0; i < ftype.m_methods.Length; i++)
            {
                Method m = map(fpod, ftype.m_methods[i]);
                merge(m, slots, nameToSlot, nameToIndex);
            }

            // break out into fields and methods
            List fields  = new List(Sys.FieldType, slots.sz());
            List methods = new List(Sys.MethodType, slots.sz());

            for (int i = 0; i < slots.sz(); i++)
            {
                Slot slot = (Slot)slots.get(i);
                if (slot is Field)
                {
                    fields.add(slot);
                }
                else
                {
                    methods.add(slot);
                }
            }
            this.m_slots       = slots.trim();
            this.m_fields      = fields.trim();
            this.m_methods     = methods.trim();
            this.m_slotsByName = nameToSlot;
            this.m_facets      = Facets.mapFacets(m_pod, ftype.m_attrs.m_facets);

            // facets
            this.m_lineNum    = m_ftype.m_attrs.m_lineNum;
            this.m_sourceFile = m_ftype.m_attrs.m_sourceFile;
        }
Beispiel #35
0
 static List checkIds(List ids)
 {
     if (ids.sz() == 0) throw ParseErr.make("No unit ids defined").val;
       for (int i=0; i<ids.sz(); ++i) checkId((string)ids.get(i));
       return (List)ids.toImmutable();
 }
Beispiel #36
0
 //////////////////////////////////////////////////////////////////////////
 // Construction
 //////////////////////////////////////////////////////////////////////////
 public static string fromChars(List chars)
 {
     if (chars.sz() == 0) return "";
       StringBuilder s = new StringBuilder(chars.sz());
       for (int i=0; i<chars.sz(); ++i)
     s.Append((char)((Long)chars.get(i)).longValue());
       return s.ToString();
 }
Beispiel #37
0
 public static Version make(List segments)
 {
     bool valid = segments.sz() > 0;
       for (int i=0; i<segments.sz(); i++)
     if (((Long)segments.get(i)).longValue() < 0) valid = false;
       if (!valid) throw ArgErr.make("Invalid Version: '" + segments + "'").val;
       return new Version(segments);
 }
Beispiel #38
0
Datei: List.cs Projekt: xored/f4
 public bool containsAny(List list)
 {
     for (int i=0; i<list.sz(); i++)
     if (index(list.get(i)) != null)
       return true;
       return false;
 }
Beispiel #39
0
            public long m_read; // Duration.nowTicks when we read

            #endregion Fields

            #region Constructors

            public CachedProps(Key key, List files)
            {
                this.m_files = files;
                this.m_modified = new long[files.sz()];
                for (int i=0; i<files.sz(); ++i)
                  this.m_modified[i] = ((File)files.get(i)).modified().ticks();
                this.m_defProps = readDef(key.m_pod, key.m_uri);
                this.m_props = read(m_defProps, key, files);
                this.m_read = Duration.nowTicks();
            }
Beispiel #40
0
        /// <summary>
        /// Compute if the method signature contains generic parameter types.
        /// </summary>
        private static int toMask(Type parent, Type returns, List pars)
        {
            // we only use generics in Sys
              if (parent.pod() != Sys.m_sysPod) return 0;

              int p = returns.isGenericParameter() ? 1 : 0;
              for (int i=0; i<pars.sz(); ++i)
            p |= ((Param)pars.get(i)).m_type.isGenericParameter() ? 1 : 0;

              int mask = 0;
              if (p != 0) mask |= GENERIC;
              return mask;
        }
Beispiel #41
0
            public override object callList(List args)
            {
                int argsSize = args == null ? 0 : args.sz();

                bool isStatic = _isStatic();
                int p = checkArgs(argsSize, isStatic, false);
                object[] a = new object[p];

                if (isStatic)
                {
                  if (args != null && a.Length > 0) args.toArray(a, 0, a.Length);
                  return m.invoke(null, a);
                }
                else
                {
                  object i = args.get(0);
                  if (a.Length > 0) args.toArray(a, 1, a.Length);
                  return m.invoke(i, a);
                }
            }
Beispiel #42
0
 public Map setList(List list, Func f)
 {
     modify();
       if (f == null)
       {
     for (int i=0; i<list.sz(); ++i)
       set(list.get(i), list.get(i));
       }
       else if (f.@params().sz() == 1)
       {
     for (int i=0; i<list.sz(); ++i)
       set(f.call(list.get(i)), list.get(i));
       }
       else
       {
     for (int i=0; i<list.sz(); ++i)
       set(f.call(list.get(i), i), list.get(i));
       }
       return this;
 }
Beispiel #43
0
        private static object doTrap(object self, string name, List args, Type type)
        {
            Slot slot = type.slot(name, true);
              if (slot is Method)
              {
            Method m = (Method)slot;
            return m.m_func.callOn(self, args);
              }
              else
              {
            Field f = (Field)slot;
            int argSize = (args == null) ? 0 : args.sz();
            if (argSize == 0)
            {
              return FanUtil.box(f.get(self));
            }

            if (argSize == 1)
            {
              object val = args.get(0);
              f.set(self, val);
              return FanUtil.box(val);
            }

            throw ArgErr.make("Invalid number of args to get or set field '" + name + "'").val;
              }
        }