コード例 #1
0
ファイル: NameTable.java プロジェクト: SteveOss/JacORB
  /**
   * check IDL scoping rules
   *
   * @throws NameAlreadyDefined or the derived IllegalRedefinition
   */
  private static void checkScopingRules(String name, IDLTypes kind) throws NameAlreadyDefined {
    if (logger.isDebugEnabled()) {
      logger.debug("NameTable.checkScopingRules:  " + name + " kind: " + kind.name());
    }

    if (kind == IDLTypes.ARGUMENT) {
      return; // no checks in outer scopes ???
    }

    StringTokenizer strtok = new StringTokenizer(name.toUpperCase(), ".");

    String scopes[] = new String[strtok.countTokens()];

    for (int i = 0; strtok.hasMoreTokens(); i++) {
      scopes[i] = strtok.nextToken();
    }

    if (logger.isDebugEnabled()) {
      logger.debug("NameTable.checkScopingRules2:  " + name + " kind: " + kind.name());
    }

    if (scopes.length > 1 && scopes[scopes.length - 2].equals(scopes[scopes.length - 1])) {
      throw new IllegalRedefinition(name);
    }
  }
コード例 #2
0
ファイル: NameTable.java プロジェクト: SteveOss/JacORB
  /**
   * copy names declared in an ancestor interface to the local scope
   *
   * @throws NameAlreadyDefined
   */
  public static synchronized void inheritFrom(String name, SymbolList ancestors)
      throws NameAlreadyDefined {
    Hashtable /*<String, IDLTypes>*/ shadowNames = new Hashtable /*<String, IDLTypes>*/();
    for (Enumeration e = names.keys(); e.hasMoreElements(); ) {
      String key = (String) e.nextElement();
      String s = null;
      if (key.indexOf('.') > 0) {
        s = key.substring(0, key.lastIndexOf('.'));
      } else {
        continue;
      }

      for (Enumeration i = ancestors.v.elements(); i.hasMoreElements(); ) {
        String anc = ((ScopedName) (i.nextElement())).resolvedName();
        if (s.equals(anc)) {
          IDLTypes kind = (IDLTypes) names.get(key);
          if (logger.isDebugEnabled()) {
            logger.debug(
                "NameTable.inheritFrom ancestor " + anc + " : key " + key + " kind " + kind);
          }

          String shadowKey = name + key.substring(key.lastIndexOf('.'));
          shadowNames.put(shadowKey, kind);

          // if the name we inherit is a typedef'd name, we need
          // to typedef the inherited name as well

          if (IDLTypes.isTypeKind(kind)) {
            if (logger.isDebugEnabled()) logger.debug("- NameTable.inherit type from:  " + key);

            TypeSpec t = TypeMap.map(anc + key.substring(key.lastIndexOf('.')));

            // t can be null for some cases where we had to put
            // Java type names (e.g. for sequence s) into the
            // name table. These need not be typedef'd again here

            if (t != null) {
              TypeMap.typedef(name + key.substring(key.lastIndexOf('.')), t);
            }
            shadowNames.put(name + key.substring(key.lastIndexOf('.')), kind);
          } else if (kind == IDLTypes.OPERATION) {
            if (logger.isDebugEnabled())
              logger.debug("- NameTable.inherit operation from:  " + key);

            NameTable.defineInheritedOperation(name + key.substring(key.lastIndexOf('.')), anc);
          } else {
            if (logger.isDebugEnabled()) {
              logger.debug("- NameTable.inherit " + kind.name() + " from:  " + key);
            }
          }

          if (!isDefined(key)) {
            throw new RuntimeException("CompilerError!");
          }
        }
      }
    }

    /* update the hashtable */

    try {
      defineShadows(shadowNames);
    } catch (NameAlreadyDefined nad) {
      if (logger.isDebugEnabled()) logger.debug("Exception ", nad);
    }
  }
コード例 #3
0
ファイル: NameTable.java プロジェクト: SteveOss/JacORB
  /**
   * define a name. If it has already been defined in this scope, an exception is thrown
   *
   * @param name The name to be defined
   * @param kind the type of name, e.g. "type"
   * @throws NameAlreadyDefined if the name is already defined
   */
  public static void define(String name, IDLTypes kind) throws NameAlreadyDefined {
    if (logger.isInfoEnabled()) {
      logger.info(
          "NameTable.define2: putting "
              + name
              + " kind "
              + kind.name()
              + " hash: "
              + name.hashCode());
    }

    /* check also for the all uppercase version of this name,
    (which is also reserved to block identifiers that
    only differ in case) */

    if (names.containsKey(name) || names.containsKey(name.toUpperCase())) {
      // if this name has been inherited, it is "shadowed"
      // in this case, it is redefined if it is not an operation
      // or interface name. If it has been
      // explicitly defined in this scope, we have an error

      if (kind == IDLTypes.MODULE) {
        // modules may be "reopened", no further checks or table entries
        return;
      }
      // This check ensures that we can't redefine a name with a
      // different type.
      // We also need to ignore any pending forward declarations.
      else if (parser.strict_identifiers
          && org.jacorb.idl.parser.strict_names
          && names.containsKey(name)
          && !names.get(name).equals(kind)
          && parser.get_pending(name) == null) {
        throw new IllegalRedefinition(name);
      } else if (!shadows.containsKey(name)
          || kind == IDLTypes.OPERATION
          || kind == IDLTypes.INTERFACE) {
        throw new NameAlreadyDefined(name);
      } else {
        // redefine
        if (logger.isInfoEnabled()) {
          logger.info("NameTable.define2: redefining  " + name);
        }

        shadows.remove(name);
        names.remove(name);

        if (IDLTypes.isTypeKind(kind)) {
          // remove the inherited type definition, a new one will be
          // added soon under this name! Addition of this line fixes
          // bug #345
          TypeMap.removeDefinition(name);
        }
      }
    }

    if (org.jacorb.idl.parser.strict_names) {
      checkScopingRules(name, kind);
    }

    /* block identifiers that only differ in case
     *
     *  JAC#584: when the name already in uppercase
     *  at first add dummy name then override it
     *  if necessary
     */
    if (org.jacorb.idl.parser.strict_names) {
      names.put(name.toUpperCase(), IDLTypes.DUMMY);
    }

    names.put(name, kind);

    if (kind == IDLTypes.OPERATION) {
      operationSources.put(name, name.substring(0, name.lastIndexOf(".")));
    }
  }