Ejemplo n.º 1
0
  @Override
  public Xobject cfold(Block block) {
    if (Type().isFparameter() && fparam_value != null) {
      // I don't know why but fparam_value is always in this form.
      if (fparam_value.Nargs() == 2 && fparam_value.getArg(1) == null) {
        Xobject value = fparam_value.getArg(0);
        return value.cfold(block);
      } else {
        XmLog.fatal("Ident.cfold: unknown form of fparam_value");
      }
    }

    if (declared_module != null) {
      XobjectDefEnv xobjDefEnv = ((FunctionBlock) block).getEnv();
      XobjectFile xobjFile = (XobjectFile) xobjDefEnv;

      if (xobjFile.findVarIdent(declared_module) == null)
        XmLog.fatal("Ident.cfold: not found module name in globalSymbols: " + declared_module);

      for (XobjectDef punit : xobjFile.getDefs()) {
        if (declared_module.equals(punit.getName())) {
          // found the module that declares this ident
          Ident ident2 = punit.getDef().findVarIdent(name);
          return ident2.cfold(block);
        }
      }
    }

    return this.copy();
  }
Ejemplo n.º 2
0
  /**
   * Fortran: create identifier.
   *
   * @param name symbol name
   * @param t type
   * @param isFcommon if is declare as common variable
   * @param isDecl 1. copy type if type is function/subroutine which is not external if true. 2. add
   *     declaration if true.
   * @param xobjFile XobjectFile in current context
   * @return created identifier
   */
  public static Ident Fident(
      String name, Xtype t, boolean isFcommon, boolean isDecl, XobjectFile xobjFile) {
    Xcode code;
    StorageClass sclass;

    if (t == null) {
      code = null;
      sclass = StorageClass.FCOMMON_NAME;
    } else {
      if (t.isFunction()) {
        code = Xcode.FUNC_ADDR;
        sclass = StorageClass.FFUNC;
        if (!t.isFexternal()) {
          if (isDecl) {
            if (t.isFsubroutine()) t = Xtype.FexternalSubroutineType.copy();
            else if (t.getRef().isBool()) t = Xtype.FexternalLogicalFunctionType.copy();
            else if (t.getRef().isIntegral()) t = Xtype.FexternalIntFunctionType.copy();
            else {
              if (xobjFile == null) throw new IllegalStateException("xobjFile is null");
              t = t.copy();
              t.setIsFexternal(true);
              t.generateId();
              xobjFile.addType(t);
            }
          } else {
            t = t.copy();
          }
        }
      } else {
        code = Xcode.VAR;
        sclass = isFcommon ? StorageClass.FCOMMON : StorageClass.FLOCAL;
      }
    }

    Xobject addr = null;
    if (t == null || t.isFunction()) isFcommon = false;

    if (code != null) {
      addr = Xcons.Symbol(code, t, name);
      addr.setIsDelayedDecl(isDecl);
      addr.setIsToBeFcommon(isFcommon);
    }

    Ident id = new Ident(name, sclass, t, addr, VarScope.LOCAL, null);
    id.setIsToBeFcommon(isFcommon);

    return id;
  }