Ejemplo n.º 1
0
        public Binding(string id, Node node, DataType type, BindingKind kind)
        {
            this.name       = id;
            this.qname      = type.Table.Path;
            this.type       = type;
            this.kind       = kind;
            this.node       = node;
            this.References = new HashSet <Node>();

            if (node is Url u)
            {
                string url = u.url;
                if (url.StartsWith("file://"))
                {
                    fileOrUrl = url.Substring("file://".Length);
                }
                else
                {
                    fileOrUrl = url;
                }
            }
            else
            {
                fileOrUrl = node.Filename;
                if (node is Identifier idNode)
                {
                    name = node.Name;
                }
            }
            SetLocationInfo(node);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Bind a name to this scope, including destructuring assignment.
 /// </summary>
 public void Bind(Analyzer analyzer, Exp target, DataType rvalue, BindingKind kind)
 {
     if (target is Identifier id)
     {
         this.Bind(analyzer, id, rvalue, kind);
     }
     else if (target is PyTuple tup)
     {
         this.Bind(analyzer, tup.values, rvalue, kind);
     }
     else if (target is PyList list)
     {
         this.Bind(analyzer, list.elts, rvalue, kind);
     }
     else if (target is AttributeAccess attr)
     {
         DataType targetType = TransformExp(analyzer, attr.Expression, this);
         setAttr(analyzer, attr, rvalue, targetType);
     }
     else if (target is ArrayRef sub)
     {
         DataType valueType = TransformExp(analyzer, sub.array, this);
         var      xform     = new TypeTransformer(this, analyzer);
         TransformExprs(analyzer, sub.subs, this);
         if (valueType is ListType t)
         {
             t.setElementType(UnionType.Union(t.eltType, rvalue));
         }
     }
     else if (target != null)
     {
         analyzer.putProblem(target, "invalid location for assignment");
     }
 }
Ejemplo n.º 3
0
        public Binding CreateBinding(string id, Node node, DataType type, BindingKind kind)
        {
            var b = new Binding(id, node, type, kind);

            RegisterBinding(b);
            return(b);
        }
Ejemplo n.º 4
0
        static void AddReadOnlyAttr(
            Analyzer analyzer,
            FunType fun,
            string name,
            DataType type,
            BindingKind kind)
        {
            Node    loc = Builtins.newDataModelUrl("the-standard-type-hierarchy");
            Binding b   = analyzer.CreateBinding(name, loc, type, kind);

            fun.Table.Update(name, b);
            b.IsSynthetic = true;
            b.IsStatic    = true;
        }
Ejemplo n.º 5
0
        public Binding Insert(Analyzer analyzer, string id, Exp node, DataType type, BindingKind kind)
        {
            Binding b = analyzer.CreateBinding(id, node, type, kind);

            if (type is ModuleType)
            {
                b.qname = type.asModuleType().qname;
            }
            else
            {
                b.qname = ExtendPath(analyzer, id);
            }
            Update(id, b);
            return(b);
        }
Ejemplo n.º 6
0
        public void Bind(Analyzer analyzer, List <Exp> xs, DataType rvalue, BindingKind kind)
        {
            switch (rvalue)
            {
            case TupleType tuple:
            {
                List <DataType> vs = tuple.eltTypes;
                if (xs.Count != vs.Count)
                {
                    ReportUnpackMismatch(analyzer, xs, vs.Count);
                }
                else
                {
                    for (int i = 0; i < xs.Count; i++)
                    {
                        this.Bind(analyzer, xs[i], vs[i], kind);
                    }
                }
                break;
            }

            case ListType list:
                Bind(analyzer, xs, list.toTupleType(xs.Count), kind);
                break;

            case DictType dict:
                Bind(analyzer, xs, dict.ToTupleType(xs.Count), kind);
                break;

            default:
                if (rvalue.isUnknownType())
                {
                    foreach (Exp x in xs)
                    {
                        this.Bind(analyzer, x, DataType.Unknown, kind);
                    }
                    break;
                }
                else if (xs.Count > 0)
                {
                    analyzer.AddProblem(xs[0].Filename,
                                        xs[0].Start,
                                        xs[xs.Count - 1].End,
                                        "unpacking non-iterable: " + rvalue);
                }
                break;
            }
        }
Ejemplo n.º 7
0
 public void Bind(Analyzer analyzer, Identifier id, DataType rvalue, BindingKind kind)
 {
     if (this.IsGlobalName(id.Name))
     {
         ISet <Binding> bs = this.Lookup(id.Name);
         if (bs != null)
         {
             foreach (Binding b in bs)
             {
                 b.addType(rvalue);
                 analyzer.putRef(id, b);
             }
         }
     }
     else
     {
         this.Insert(analyzer, id.Name, id, rvalue, kind);
     }
 }
Ejemplo n.º 8
0
 public void Bind(Analyzer analyzer, List <Exp> xs, DataType rvalue, BindingKind kind)
 {
     if (rvalue is TupleType)
     {
         List <DataType> vs = ((TupleType)rvalue).eltTypes;
         if (xs.Count != vs.Count)
         {
             ReportUnpackMismatch(analyzer, xs, vs.Count);
         }
         else
         {
             for (int i = 0; i < xs.Count; i++)
             {
                 this.Bind(analyzer, xs[i], vs[i], kind);
             }
         }
     }
     else
     {
         if (rvalue is ListType)
         {
             Bind(analyzer, xs, ((ListType)rvalue).toTupleType(xs.Count), kind);
         }
         else if (rvalue is DictType)
         {
             Bind(analyzer, xs, ((DictType)rvalue).ToTupleType(xs.Count), kind);
         }
         else if (rvalue.isUnknownType())
         {
             foreach (Exp x in xs)
             {
                 this.Bind(analyzer, x, DataType.Unknown, kind);
             }
         }
         else if (xs.Count > 0)
         {
             analyzer.putProblem(xs[0].Filename,
                                 xs[0].Start,
                                 xs[xs.Count - 1].End,
                                 "unpacking non-iterable: " + rvalue);
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Bind a name to this scope, including destructuring assignment.
        /// </summary>
        public void Bind(Analyzer analyzer, Exp target, DataType rvalue, BindingKind kind)
        {
            switch (target)
            {
            case Identifier id:
                this.Bind(analyzer, id, rvalue, kind);
                break;

            case PyTuple tup:
                this.Bind(analyzer, tup.values, rvalue, kind);
                break;

            case PyList list:
                this.Bind(analyzer, list.elts, rvalue, kind);
                break;

            case AttributeAccess attr:
                DataType targetType = TransformExp(analyzer, attr.Expression, this);
                setAttr(analyzer, attr, rvalue, targetType);
                break;

            case ArrayRef sub:
                DataType valueType = TransformExp(analyzer, sub.array, this);
                var      xform     = new TypeTransformer(this, analyzer);
                TransformExprs(analyzer, sub.subs, this);
                if (valueType is ListType t)
                {
                    t.setElementType(UnionType.Union(t.eltType, rvalue));
                }
                break;

            default:
                if (target != null)
                {
                    analyzer.AddProblem(target, "invalid location for assignment");
                }
                break;
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Bind a name to this scope, including destructuring assignment.
        /// </summary>
        public void Bind(Analyzer analyzer, Exp target, DataType rvalue, BindingKind kind)
        {
            if (target is Identifier)
            {
                this.Bind(analyzer, (Identifier)target, rvalue, kind);
            }
            else if (target is PyTuple)
            {
                this.Bind(analyzer, ((PyTuple)target).values, rvalue, kind);
            }
            else if (target is PyList)
            {
                this.Bind(analyzer, ((PyList)target).elts, rvalue, kind);
            }
            else if (target is AttributeAccess)
            {
                var      attr       = (AttributeAccess)target;
                DataType targetType = transformExpr(analyzer, attr.Expression, this);
                setAttr(analyzer, attr, rvalue, targetType);
            }
            else if (target is ArrayRef)
            {
                ArrayRef sub = (ArrayRef)target;

                DataType valueType = transformExpr(analyzer, sub.array, this);
                var      xform     = new TypeTransformer(this, analyzer);
                transformExprs(analyzer, sub.subs, this);
                if (valueType is ListType)
                {
                    ListType t = (ListType)valueType;
                    t.setElementType(UnionType.Union(t.eltType, rvalue));
                }
            }
            else if (target != null)
            {
                analyzer.putProblem(target, "invalid location for assignment");
            }
        }
Ejemplo n.º 11
0
 public void Bind(Analyzer analyzer, List<Exp> xs, DataType rvalue, BindingKind kind)
 {
     if (rvalue is TupleType)
     {
         List<DataType> vs = ((TupleType) rvalue).eltTypes;
         if (xs.Count != vs.Count)
         {
             ReportUnpackMismatch(analyzer, xs, vs.Count);
         }
         else
         {
             for (int i = 0; i < xs.Count; i++)
             {
                 this.Bind(analyzer, xs[i], vs[i], kind);
             }
         }
     }
     else
     {
         if (rvalue is ListType)
         {
             Bind(analyzer, xs, ((ListType) rvalue).toTupleType(xs.Count), kind);
         }
         else if (rvalue is DictType)
         {
             Bind(analyzer, xs, ((DictType) rvalue).toTupleType(xs.Count), kind);
         }
         else if (rvalue.isUnknownType())
         {
             foreach (Exp x in xs)
             {
                 this.Bind(analyzer, x, DataType.Unknown, kind);
             }
         }
         else if (xs.Count > 0)
         {
             analyzer.putProblem(xs[0].Filename,
                     xs[0].Start,
                     xs[xs.Count - 1].End,
                     "unpacking non-iterable: " + rvalue);
         }
     }
 }
Ejemplo n.º 12
0
 // iterator
 public void BindIterator(Analyzer analyzer, Exp target, Exp iter, DataType iterType, BindingKind kind)
 {
     if (iterType is ListType)
     {
         this.Bind(analyzer, target, ((ListType) iterType).eltType, kind);
     }
     else if (iterType is TupleType)
     {
         this.Bind(analyzer, target, ((TupleType) iterType).toListType().eltType, kind);
     }
     else
     {
         ISet<Binding> ents = iterType.Table.LookupAttribute("__iter__");
         if (ents != null)
         {
             foreach (Binding ent in ents)
             {
                 if (ent == null || !(ent.type is FunType))
                 {
                     if (!iterType.isUnknownType())
                     {
                         analyzer.putProblem(iter, "not an iterable type: " + iterType);
                     }
                     this.Bind(analyzer, target, DataType.Unknown, kind);
                 }
                 else
                 {
                     this.Bind(analyzer, target, ((FunType) ent.type).getReturnType(), kind);
                 }
             }
         }
         else
         {
             this.Bind(analyzer, target, DataType.Unknown, kind);
         }
     }
 }
 public ConstBindingViewModel(BindingKind kind, int value)
 {
     Kind  = kind;
     Value = value;
 }
Ejemplo n.º 14
0
 protected void update(string name, Url url, DataType type, BindingKind kind)
 {
     table.Insert(outer.analyzer, name, url, type, kind).IsBuiltin = true;
 }
Ejemplo n.º 15
0
 public Binding Insert(Analyzer analyzer, string id, Exp node, DataType type, BindingKind kind)
 {
     Binding b = analyzer.CreateBinding(id, node, type, kind);
     if (type is ModuleType)
     {
         b.qname = type.asModuleType().qname;
     }
     else
     {
         b.qname = extendPath(analyzer, id);
     }
     Update(id, b);
     return b;
 }
Ejemplo n.º 16
0
 public void Bind(Analyzer analyzer, Identifier id, DataType rvalue, BindingKind kind)
 {
     if (this.IsGlobalName(id.Name))
     {
         ISet<Binding> bs = this.Lookup(id.Name);
         if (bs != null)
         {
             foreach (Binding b in bs)
             {
                 b.addType(rvalue);
                 analyzer.putRef(id, b);
             }
         }
     }
     else
     {
         this.Insert(analyzer, id.Name, id, rvalue, kind);
     }
 }
Ejemplo n.º 17
0
 // iterator
 public void BindIterator(Analyzer analyzer, Exp target, Exp iter, DataType iterType, BindingKind kind)
 {
     if (iterType is ListType list)
     {
         this.Bind(analyzer, target, list.eltType, kind);
     }
     else if (iterType is TupleType tuple)
     {
         this.Bind(analyzer, target, tuple.ToListType().eltType, kind);
     }
     else
     {
         ISet <Binding>?ents = iterType.Table.LookupAttribute("__iter__");
         if (ents != null)
         {
             foreach (Binding ent in ents)
             {
                 if (!(ent?.Type is FunType fun))
                 {
                     if (!iterType.IsUnknownType())
                     {
                         analyzer.AddProblem(iter, "not an iterable type: " + iterType);
                     }
                     this.Bind(analyzer, target, DataType.Unknown, kind);
                 }
                 else
                 {
                     this.Bind(analyzer, target, fun.GetReturnType(), kind);
                 }
             }
         }
Ejemplo n.º 18
0
        public Binding Insert(Analyzer analyzer, string id, Module node, DataType type, BindingKind kind)
        {
            Binding b = analyzer.CreateBinding(id, node, type, kind);

            if (type is ModuleType mt)
            {
                b.qname = mt.qname;
            }
            else
            {
                b.qname = analyzer.ExtendPath(this.Path, id);
            }
            Update(id, b);
            return(b);
        }
 public BindingViewModel(BindingKind kind, FieldViewModel source, FieldViewModel target)
 {
     Kind   = kind;
     Source = source;
     Target = target;
 }
Ejemplo n.º 20
0
 public Binding CreateBinding(string id, Node node, DataType type, BindingKind kind)
 {
     var b = new Binding(id, node, type, kind);
     RegisterBinding(b);
     return b;
 }
Ejemplo n.º 21
0
 // iterator
 public void BindIterator(Analyzer analyzer, Exp target, Exp iter, DataType iterType, BindingKind kind)
 {
     if (iterType is ListType)
     {
         this.Bind(analyzer, target, ((ListType)iterType).eltType, kind);
     }
     else if (iterType is TupleType)
     {
         this.Bind(analyzer, target, ((TupleType)iterType).ToListType().eltType, kind);
     }
     else
     {
         ISet <Binding> ents = iterType.Table.LookupAttribute("__iter__");
         if (ents != null)
         {
             foreach (Binding ent in ents)
             {
                 if (ent == null || !(ent.type is FunType))
                 {
                     if (!iterType.isUnknownType())
                     {
                         analyzer.putProblem(iter, "not an iterable type: " + iterType);
                     }
                     this.Bind(analyzer, target, DataType.Unknown, kind);
                 }
                 else
                 {
                     this.Bind(analyzer, target, ((FunType)ent.type).GetReturnType(), kind);
                 }
             }
         }
         else
         {
             this.Bind(analyzer, target, DataType.Unknown, kind);
         }
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Bind a name to this scope, including destructuring assignment.
        /// </summary>
        public void Bind(Analyzer analyzer, Exp target, DataType rvalue, BindingKind kind)
        {
            if (target is Identifier)
            {
                this.Bind(analyzer, (Identifier) target, rvalue, kind);
            }
            else if (target is PyTuple)
            {
                this.Bind(analyzer, ((PyTuple) target).values, rvalue, kind);
            }
            else if (target is PyList)
            {
                this.Bind(analyzer, ((PyList) target).elts, rvalue, kind);
            }
            else if (target is AttributeAccess)
            {
                var attr = (AttributeAccess) target;
                DataType targetType = transformExpr(analyzer, attr.Expression, this);
                setAttr(analyzer, attr, rvalue, targetType);
            }
            else if (target is ArrayRef)
            {
                ArrayRef sub = (ArrayRef) target;

                DataType valueType = transformExpr(analyzer, sub.array, this);
                var xform = new TypeTransformer(this, analyzer);
                transformExprs(analyzer, sub.subs, this);
                if (valueType is ListType)
                {
                    ListType t = (ListType) valueType;
                    t.setElementType(UnionType.Union(t.eltType, rvalue));
                }
            }
            else if (target != null)
            {
                analyzer.putProblem(target, "invalid location for assignment");
            }
        }