Пример #1
0
  /**
   * Attempts precise name lookup using information stored in the program database starting with the
   * global namespace.
   *
   * @param startingFrom a starting point for lookup; names will be looked up in the scope
   *     associated with startingPoint and in containing scopes.
   * @param name name to look up
   * @return
   */
  Entity lookupLocal(Entity startingFrom, String name) {
    String[] splitName = name.split("::");
    // Try to find the first name element
    Entity look = null;

    if (splitName[0].equals("")) {
      look = m_program.getGlobalNamespace();
    } else {
      Entity context = startingFrom;
      while (context != null && look == null) {
        look = Utils.lookup(context, splitName[0]);
        context = up(context);
      }
    }
    // Resolve remaining symbols
    for (int i = 1; i < splitName.length && look != null; ++i) {
      look = Utils.lookup(look, splitName[i]);
    }
    return look;
  }
Пример #2
0
 Scope<Namespace> lookupExternal(Entity origin) {
   if (origin == m_program.getGlobalNamespace()) {
     return m_program.getExternals();
   } else if (origin.hasContainer()) {
     Scope<Namespace> container = lookupExternal(origin.getContainer());
     if (container != null) {
       Entity look = Utils.lookup(container, origin.getName());
       if (look == null) return container;
       else if (look instanceof Namespace) return ((Namespace) look).getScope();
       else return container;
     }
   }
   // - fall back to global scope
   return m_program.getExternals();
 }
Пример #3
0
 /**
  * Approximates name lookup using the information contained in some internal maps.
  *
  * @param name name to look up
  * @return
  */
 Entity lookupApprox(String name) {
   Entity base = null;
   // Look name up in full-name map
   Object byFullName = m_entitiesByFullName.get(name);
   if (byFullName != null) {
     base = (Entity) byFullName;
   } else {
     // Look name up in short-name map
     String[] splitName = name.split("::");
     Object byName = m_entitiesByName.get(splitName[0]);
     for (int i = 1; i < splitName.length && byName != null; ++i) {
       byName = Utils.lookup((Entity) byName, splitName[i]);
     }
     if (byName != null) base = (Entity) byName;
   }
   return base;
 }
Пример #4
0
 /**
  * Attempts lookup in the program database's external reference.
  *
  * @param name name to look for
  * @return
  */
 Entity lookupExternal(Entity origin, String name) {
   Scope<Namespace> context = lookupExternal(origin);
   Entity look = Utils.lookup(context, name);
   return look;
 }