コード例 #1
0
ファイル: Ident.java プロジェクト: clementval/omni-compiler
  @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();
  }
コード例 #2
0
ファイル: Ident.java プロジェクト: clementval/omni-compiler
  /**
   * 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;
  }
コード例 #3
0
ファイル: Ident.java プロジェクト: clementval/omni-compiler
 public int getCorank() {
   if (codimensions != null) { // for coarray C temporarily (#284)
     return codimensions.Nargs() + 1;
   } else { // for coarray Fortran (#060)
     return (Type() == null) ? 0 : Type().getCorank();
   }
 }
コード例 #4
0
ファイル: Ident.java プロジェクト: clementval/omni-compiler
  @Override
  public String toString() {
    if (getStorageClass() == StorageClass.REG) {
      return "[0x"
          + Integer.toHexString(num)
          + " "
          + (type == null ? "*" : type.toString())
          + " () *]";
    }

    StringBuilder b = new StringBuilder(256);
    b.append("[");
    b.append(name == null ? "*" : name);
    b.append(" ");
    b.append(stg_class == null ? "*" : stg_class.toXcodeString());
    b.append(" ");
    b.append(type == null ? "*" : type.toString());
    b.append(" ");
    b.append(value == null ? "()" : value.toString());

    /* bit_field, bit_field_expr, enum_value are exclusively set */
    b.append(" ");
    if (bit_field != 0 || bit_field_expr != null) {
      if (bit_field != 0) b.append(bit_field);
      else b.append(bit_field_expr.toString());
    } else if (enum_value != null) {
      b.append(" ");
      b.append(enum_value.toString());
    } else {
      b.append("*");
    }

    b.append(declared ? " D" : "");

    if (gcc_attrs != null) {
      b.append(" ");
      b.append(gcc_attrs.toString());
    }

    b.append("]");

    return b.toString();
  }