sz() public method

public sz ( ) : int
return int
Beispiel #1
0
            public override object callOn(object target, List args)
            {
                int  argsSize     = args == null ? 0 : args.sz();
                bool dotnetStatic = _isStatic();
                bool fanStatic    = ((m.m_flags & (FConst.Static | FConst.Ctor)) != 0);

                if (dotnetStatic && !fanStatic)
                {
                    // if Java static doesn't match Fantom static, then this is
                    // a FanXXX method which we need to call as Java static
                    int      p = checkArgs(argsSize, false, true);
                    object[] a = new object[p + 1];
                    a[0] = target;
                    if (args != null && a.Length > 0)
                    {
                        args.copyInto(a, 1, a.Length - 1);
                    }
                    return(m.invoke(null, a));
                }
                else
                {
                    // we don't include target as part of arguments
                    int      p = checkArgs(argsSize, dotnetStatic, true);
                    object[] a = new object[p];
                    if (args != null && a.Length > 0)
                    {
                        args.toArray(a, 0, a.Length);
                    }
                    return(m.invoke(target, a));
                }
            }
Beispiel #2
0
            private int checkArgs(int args, bool isStatic, bool isCallOn)
            {
                // compuate min/max parameters - reflect contains all the method versions
                // with full pars at index zero, and full defaults at reflect.Length-1
                int max = m_params.sz();

                if (!isStatic)
                {
                    max--;
                }
                int min = max - m.m_reflect.Length + 1;

                // do checking
                if (isStatic || isCallOn)
                {
                    if (args < min)
                    {
                        throw ArgErr.make("Too few arguments: " + args + " < " + min + ".." + max).val;
                    }
                }
                else
                {
                    if (args < min + 1)
                    {
                        throw ArgErr.make("Too few arguments: " + args + " < instance+" + min + ".." + max).val;
                    }
                    args--;
                }

                // return size of arguments to pass to java method
                return(args <= max ? args : max);
            }
Beispiel #3
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 #4
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 #5
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 #6
0
        public static Version fromStr(string s, bool check)
        {
            List segments = new List(Sys.IntType, 4);
            int  seg      = -1;
            bool valid    = true;
            int  len      = s.Length;

            for (int i = 0; i < len; ++i)
            {
                int c = s[i];
                if (c == '.')
                {
                    if (seg < 0 || i + 1 >= len)
                    {
                        valid = false; break;
                    }
                    segments.add(Long.valueOf(seg));
                    seg = -1;
                }
                else
                {
                    if ('0' <= c && c <= '9')
                    {
                        if (seg < 0)
                        {
                            seg = c - '0';
                        }
                        else
                        {
                            seg = seg * 10 + (c - '0');
                        }
                    }
                    else
                    {
                        valid = false; break;
                    }
                }
            }
            if (seg >= 0)
            {
                segments.add(Long.valueOf(seg));
            }

            if (!valid || segments.sz() == 0)
            {
                if (check)
                {
                    throw ParseErr.make("Version", s).val;
                }
                else
                {
                    return(null);
                }
            }

            return(new Version(segments));
        }
Beispiel #7
0
        /// <summary>
        /// Constructor used by GenericType and we are given the generic
        /// method that is being parameterized.
        /// </summary>
        public Method(Type parent, string name, int flags, Facets facets, int lineNum, Type returns, Type inheritedReturns, List pars, Method generic)
            : base(parent, name, flags, facets, lineNum)
        {
            List fparams = pars.ro();
              if ((flags & (FConst.Static|FConst.Ctor)) == 0)
              {
            object[] temp = new object[pars.sz()+1];
            temp[0] = new Param("this", parent, 0);
            pars.copyInto(temp, 1, pars.sz());
            fparams = new List(Sys.ParamType, temp);
              }

              this.m_func = new MethodFunc(this, returns, fparams);
              this.m_params = pars;
              this.m_inheritedReturns = inheritedReturns;
              this.m_mask = (generic != null) ? 0 : toMask(parent, returns, pars);
              this.m_generic = generic;
        }
Beispiel #8
0
 public static void removeHandler(Func func)
 {
     lock (lockObj)
     {
         List temp = new List(Sys.FuncType, m_handlers);
         temp.remove(func);
         m_handlers = (Func[])temp.toArray(new Func[temp.sz()]);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Constructor used by GenericType and we are given the generic
        /// method that is being parameterized.
        /// </summary>
        public Method(Type parent, string name, int flags, Facets facets, int lineNum, Type returns, Type inheritedReturns, List pars, Method generic)
            : base(parent, name, flags, facets, lineNum)
        {
            List fparams = pars.ro();

            if ((flags & (FConst.Static | FConst.Ctor)) == 0)
            {
                object[] temp = new object[pars.sz() + 1];
                temp[0] = new Param("this", parent, 0);
                pars.copyInto(temp, 1, pars.sz());
                fparams = new List(Sys.ParamType, temp);
            }

            this.m_func             = new MethodFunc(this, returns, fparams);
            this.m_params           = pars;
            this.m_inheritedReturns = inheritedReturns;
            this.m_mask             = (generic != null) ? 0 : toMask(parent, returns, pars);
            this.m_generic          = generic;
        }
Beispiel #10
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 #11
0
        public static void addHandler(Func func)
        {
            if (!func.isImmutable())
            throw NotImmutableErr.make("handler must be immutable").val;

              lock (lockObj)
              {
            List temp = new List(Sys.FuncType, m_handlers).add(func);
            m_handlers = (Func[])temp.toArray(new Func[temp.sz()]);
              }
        }
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
        public static void addHandler(Func func)
        {
            if (!func.isImmutable())
            {
                throw NotImmutableErr.make("handler must be immutable").val;
            }

            lock (lockObj)
            {
                List temp = new List(Sys.FuncType, m_handlers).add(func);
                m_handlers = (Func[])temp.toArray(new Func[temp.sz()]);
            }
        }
Beispiel #14
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 #15
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 #16
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 #17
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 #18
0
        public List split(string s, long limit)
        {
            int  l      = (limit < 0) ? 0 : (int)limit;
            List result = new List(m_pattern.Split(s, l));

            // to match java we need to discard any trailing
            // emptys strings (use limit, not l)
            if (limit == 0)
            {
                while (result.sz() > 0 && (result.last() as string).Length == 0)
                {
                    result.pop();
                }
            }

            return(result);
        }
Beispiel #19
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 #20
0
        public static Version fromStr(string s, bool check)
        {
            List segments = new List(Sys.IntType, 4);
              int seg = -1;
              bool valid = true;
              int len = s.Length;
              for (int i=0; i<len; ++i)
              {
            int c = s[i];
            if (c == '.')
            {
              if (seg < 0 || i+1>=len) { valid = false; break; }
              segments.add(Long.valueOf(seg));
              seg = -1;
            }
            else
            {
              if ('0' <= c && c <= '9')
              {
            if (seg < 0) seg = c-'0';
            else seg = seg*10 + (c-'0');
              }
              else
              {
            valid = false; break;
              }
            }
              }
              if (seg >= 0) segments.add(Long.valueOf(seg));

              if (!valid || segments.sz() == 0)
              {
            if (check)
              throw ParseErr.make("Version", s).val;
            else
              return null;
              }

              return new Version(segments);
        }
Beispiel #21
0
        public static List splitws(String val)
        {
            List toks = new List(Sys.StrType, 16);
            int  len  = val.Length;

            while (len > 0 && val[len - 1] <= ' ')
            {
                --len;
            }
            int x = 0;

            while (x < len && val[x] <= ' ')
            {
                ++x;
            }
            for (int i = x; i < len; ++i)
            {
                if (val[i] > ' ')
                {
                    continue;
                }
                toks.add(val.Substring(x, i - x));
                x = i + 1;
                while (x < len && val[x] <= ' ')
                {
                    ++x;
                }
                i = x;
            }
            if (x <= len)
            {
                toks.add(val.Substring(x, len - x));
            }
            if (toks.sz() == 0)
            {
                toks.add("");
            }
            return(toks);
        }
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
            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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
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 #31
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 #32
0
 public static void removeHandler(Func func)
 {
     lock (lockObj)
       {
     List temp = new List(Sys.FuncType, m_handlers);
     temp.remove(func);
     m_handlers = (Func[])temp.toArray(new Func[temp.sz()]);
       }
 }
Beispiel #33
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 #34
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 #35
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 #36
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 #37
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 #38
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 #39
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 #40
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 #41
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 #42
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 #43
0
 public static List splitws(String val)
 {
     List toks = new List(Sys.StrType, 16);
       int len = val.Length;
       while (len > 0 && val[len-1] <= ' ') --len;
       int x = 0;
       while (x < len && val[x] <= ' ') ++x;
       for (int i=x; i<len; ++i)
       {
     if (val[i] > ' ') continue;
     toks.add(val.Substring(x, i-x));
     x = i + 1;
     while (x < len && val[x] <= ' ') ++x;
     i = x;
       }
       if (x <= len) toks.add(val.Substring(x, len-x));
       if (toks.sz() == 0) toks.add("");
       return toks;
 }
Beispiel #44
0
            public override object callOn(object target, List args)
            {
                int argsSize = args == null ? 0 : args.sz();
                bool dotnetStatic = _isStatic();
                bool fanStatic = ((m.m_flags & (FConst.Static|FConst.Ctor)) != 0);

                if (dotnetStatic && !fanStatic)
                {
                  // if Java static doesn't match Fantom static, then this is
                  // a FanXXX method which we need to call as Java static
                  int p = checkArgs(argsSize, false, true);
                  object[] a = new object[p+1];
                  a[0] = target;
                  if (args != null && a.Length > 0) args.copyInto(a, 1, a.Length-1);
                  return m.invoke(null, a);
                }
                else
                {
                  // we don't include target as part of arguments
                  int p = checkArgs(argsSize, dotnetStatic, true);
                  object[] a = new object[p];
                  if (args != null && a.Length > 0) args.toArray(a, 0, a.Length);
                  return m.invoke(target, a);
                }
            }
Beispiel #45
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 #46
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 #47
0
Datei: Regex.cs Projekt: xored/f4
        public List split(string s, long limit)
        {
            int l = (limit < 0) ? 0 : (int)limit;
              List result = new List(m_pattern.Split(s, l));

              // to match java we need to discard any trailing
              // emptys strings (use limit, not l)
              if (limit == 0)
            while (result.sz() > 0 && (result.last() as string).Length == 0)
              result.pop();

              return result;
        }
Beispiel #48
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;
        }