Ejemplo n.º 1
0
 public override HeronValue GetFieldOrMethod(string name)
 {
     if (!hinterface.HasMethod(name))
     {
         base.GetFieldOrMethod(name);
     }
     return(obj.GetFieldOrMethod(name));
 }
Ejemplo n.º 2
0
        public HeronValue LookupName(string s)
        {
            // Look in the scopes starting with the innermost
            // and moving to the outermost.
            // The outermost scope contains the arguments
            for (int i = scopes.Count; i > 0; --i)
            {
                Scope tbl = scopes[i - 1];
                if (tbl.HasName(s))
                {
                    return(tbl[s]);
                }
            }

            // Nothing found in the local vars,
            // So we look in the "this" pointer (called "self")
            // Note that "self" may be a class instance, or a moduleDef
            // instance
            if (self != null)
            {
                HeronValue r = self.GetFieldOrMethod(s);
                if (r != null)
                {
                    return(r);
                }

                // Nothing found in the "this" pointer. So
                // we look if it has an enclosing module instance pointer.
                // And use that

                ModuleInstance mi = self.GetModuleInstance();
                if (mi != null)
                {
                    r = mi.GetFieldOrMethod(s);
                    if (r != null)
                    {
                        return(r);
                    }
                }
            }

            // Look to see if the name is a type in the current module definition.
            if (moduleDef != null)
            {
                HeronType t = moduleDef.FindType(s);
                if (t != null)
                {
                    return(t);
                }

                // Look to see if the name is a type in one of the imported module definitions.
                List <HeronType> candidates = new List <HeronType>();
                foreach (ModuleDefn defn in moduleDef.GetImportedModuleDefns())
                {
                    t = defn.FindType(s);
                    if (t != null)
                    {
                        candidates.Add(t);
                    }
                }

                if (candidates.Count > 1)
                {
                    throw new Exception("Ambiguous name resolution. Multiple modules contain a type named " + s);
                }
                if (candidates.Count == 1)
                {
                    return(candidates[1]);
                }
            }

            return(null);
        }