Insert() public method

public Insert ( Analyzer analyzer, string id, Exp node, DataType type, BindingKind kind ) : Binding
analyzer Analyzer
id string
node Exp
type DataType
kind BindingKind
return Binding
Ejemplo n.º 1
0
 public DataType VisitImport(ImportStatement i)
 {
     foreach (var a in i.names)
     {
         DataType mod = analyzer.LoadModule(a.orig.segs, scope);
         if (mod == null)
         {
             analyzer.putProblem(i, "Cannot load module");
         }
         else if (a.alias != null)
         {
             scope.Insert(analyzer, a.alias.Name, a.alias, mod, BindingKind.VARIABLE);
         }
     }
     return(DataType.Cont);
 }
Ejemplo n.º 2
0
        public DataType LoadModule(List<Name> name, State state)
        {
            if (name.Count == 0)
            {
                return null;
            }

            string qname = MakeQname(name);
            DataType mt = getBuiltinModule(qname);
            if (mt != null)
            {
                state.Insert(
                        this,
                        name[0].Name,
                        new Url(Builtins.LIBRARY_URL + mt.Table.Path + ".html"),
                        mt, BindingKind.SCOPE);
                return mt;
            }

            // If there are more than one segment
            // load the packages first
            DataType prev = null;
            string startPath = locateModule(name[0].Name);

            if (startPath == null)
            {
                return null;
            }

            string path = startPath;
            for (int i = 0; i < name.Count; i++)
            {
                path = FileSystem.CombinePath(path, name[i].Name);
                string initFile = FileSystem.CombinePath(path, "__init__.py");
                if (FileSystem.FileExists(initFile))
                {
                    DataType mod = LoadFile(initFile);
                    if (mod == null)
                    {
                        return null;
                    }

                    if (prev != null)
                    {
                        prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }
                    else
                    {
                        state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }

                    prev = mod;

                }
                else if (i == name.Count - 1)
                {
                    string startFile = path + suffix;
                    if (FileSystem.FileExists( startFile))
                    {
                        DataType mod = LoadFile(startFile);
                        if (mod == null)
                        {
                            return null;
                        }
                        if (prev != null)
                        {
                            prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        else
                        {
                            state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        prev = mod;
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            return prev;
        }
Ejemplo n.º 3
0
        public DataType LoadModule(List <Name> name, State state)
        {
            if (name.Count == 0)
            {
                return(null);
            }

            string   qname = MakeQname(name);
            DataType mt    = GetBuiltinModule(qname);

            if (mt != null)
            {
                state.Insert(
                    this,
                    name[0].Name,
                    new Url(Builtins.LIBRARY_URL + mt.Table.Path + ".html"),
                    mt, BindingKind.SCOPE);
                return(mt);
            }

            // If there are more than one segment load the packages first
            string startPath = LocateModule(name[0].Name);

            if (startPath == null)
            {
                return(null);
            }

            DataType prev = null;
            string   path = startPath;

            for (int i = 0; i < name.Count; i++)
            {
                path = FileSystem.CombinePath(path, name[i].Name);
                string initFile = FileSystem.CombinePath(path, "__init__.py");
                if (FileSystem.FileExists(initFile))
                {
                    DataType mod = LoadFile(initFile);
                    if (mod == null)
                    {
                        return(null);
                    }

                    if (prev != null)
                    {
                        prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }
                    else
                    {
                        state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                    }

                    prev = mod;
                }
                else if (i == name.Count - 1)
                {
                    string startFile = path + suffix;
                    if (FileSystem.FileExists(startFile))
                    {
                        DataType mod = LoadFile(startFile);
                        if (mod == null)
                        {
                            return(null);
                        }
                        if (prev != null)
                        {
                            prev.Table.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        else
                        {
                            state.Insert(this, name[i].Name, name[i], mod, BindingKind.VARIABLE);
                        }
                        prev = mod;
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            return(prev);
        }