Пример #1
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;
  }
Пример #2
0
  public static Ident Var(String name, Xtype t, Xtype addrt, VarScope scope, Xobject codimensions) {
    StorageClass sclass;
    Xcode addrCode;

    if (XmOption.isLanguageC()) {
      sclass = (scope == VarScope.PARAM) ? StorageClass.PARAM : StorageClass.AUTO;
      addrCode = t.isArray() ? Xcode.ARRAY_ADDR : Xcode.VAR_ADDR;
    } else {
      sclass = (scope == VarScope.PARAM) ? StorageClass.FPARAM : StorageClass.FLOCAL;
      addrCode = Xcode.VAR;
    }

    return new Ident(name, sclass, t, Xcons.Symbol(addrCode, addrt, name), scope, codimensions);
  }
Пример #3
0
 public static Ident TempVar(int num, Xtype t) {
   if (t.isArray()) {
     t = Xtype.Pointer(t.getRef()); // convert to pointer
     return new Ident(num, t);
   } else return new Ident(num, t);
 }
Пример #4
0
 public static Ident Param(String name, Xtype t) {
   return Var(name, t, Xtype.Pointer(t), VarScope.PARAM);
 }
Пример #5
0
 public static Ident Local(String name, Xtype t) {
   if (XmOption.isLanguageC()) return Local(name, t, Xtype.Pointer(t));
   return Fident(name, t);
 }