示例#1
0
 public Xobject Index(Xobject i) {
   if (type.isArray() || value.code == Xcode.VAR_ADDR || value.code == Xcode.ARRAY_ADDR)
     return Xcons.PointerRef(Xcons.binaryOp(Xcode.PLUS_EXPR, Ref(), i));
   if (type.isPointer()) return Xcons.PointerRef(Xcons.binaryOp(Xcode.PLUS_EXPR, value, i));
   XmLog.fatal("Index: not Pointer");
   return null;
 }
示例#2
0
 // return value for refernce 'id'
 public Xobject Ref() {
   if (getStorageClass() == StorageClass.REG) return Xcons.Int(Xcode.REG, type, num);
   if (type.isFunction()) return value;
   if (value == null) {
     XmLog.fatal("value is null : " + toString());
   }
   return Xcons.PointerRef(value);
 }
示例#3
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);
  }
示例#4
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;
  }
示例#5
0
 public Xobject callSubroutine(Xobject args) {
   return Xcons.List(Xcode.EXPR_STATEMENT, Call(args));
 }
示例#6
0
 public Xobject Call(Xobject args) {
   if (type.isFunction()) return Xcons.List(Xcode.FUNCTION_CALL, type.getRef(), value, args);
   else XmLog.fatal("Call: not Function");
   return null;
 }
示例#7
0
 public Xobject Call() {
   return Call(Xcons.List());
 }
示例#8
0
 // return value for referenece 'id[i]' == *(id + i)
 public Xobject Index(int i) {
   return Index(Xcons.IntConstant(i));
 }