void genJavaClassBodyComponents(PrintWriter writer, int depth) {
    for (Iterator it = components.iterator(); it.hasNext(); ) {
      TypeNode tn = (TypeNode) it.next();

      tn.genJavaDeclaration(writer, depth);
    }
  }
 /** @see de.unika.ipd.grgen.ast.BaseNode#resolveLocal() */
 @Override
 protected boolean resolveLocal() {
   boolean res = true;
   for (TypeNode typeNode : getType()) {
     res &= typeNode.resolve();
   }
   return res;
 }
 String javaParams() {
   StringBuffer sb = new StringBuffer();
   for (Iterator it = components.iterator(); it.hasNext(); ) {
     TypeNode tn = (TypeNode) it.next();
     sb.append(tn.javaParam());
     if (it.hasNext()) {
       sb.append(", ");
     }
   }
   return sb.toString();
 }
 void genJavaWritingClassBody(PrintWriter writer, int depth, String className) {
   genJavaClassBodyComponents(writer, depth);
   writer.println();
   indent(writer, depth);
   writer.println(className + "(" + javaParams() + ") {");
   for (Iterator it = components.iterator(); it.hasNext(); ) {
     TypeNode tn = (TypeNode) it.next();
     indent(writer, depth + 1);
     writer.println("this." + tn.name() + " = " + tn.name() + ";");
   }
   indent(writer, depth);
   writer.println("}");
 }
Exemplo n.º 5
0
  public Type childExpectedType(Expr child, AscriptionVisitor av) {
    TypeSystem ts = av.typeSystem();

    if (child == expr) {
      if (castType.type().isReference()) {
        return ts.Object();
      } else if (castType.type().isNumeric()) {
        return ts.Double();
      } else if (castType.type().isBoolean()) {
        return ts.Boolean();
      }
    }

    return child.type();
  }
Exemplo n.º 6
0
  /** Type check the expression. */
  public Node typeCheck(TypeChecker tc) throws SemanticException {
    TypeSystem ts = tc.typeSystem();

    if (!ts.isCastValid(expr.type(), castType.type())) {
      throw new SemanticException(
          "Cannot cast the expression of type \""
              + expr.type()
              + "\" to type \""
              + castType.type()
              + "\".",
          position());
    }

    return type(castType.type());
  }
Exemplo n.º 7
0
 public void addItem(ItemRecord itemRecord) {
   sorted = false;
   ERepositoryObjectType type = itemRecord.getType();
   boolean isdelete = itemRecord.getProperty().getItem().getState().isDeleted();
   if (isdelete) {
     type = ERepositoryObjectType.RECYCLE_BIN;
   }
   types.add(type);
   TypeNode folder = typeMap.get(type);
   if (folder == null) {
     folder = new TypeNode(type);
     typeMap.put(type, folder);
   }
   folder.add(itemRecord);
 }
Exemplo n.º 8
0
  /**
   * Check the types of this cast. Check if the expression can be casted to the given type.
   *
   * @see de.unika.ipd.grgen.ast.BaseNode#typeCheckLocal()
   */
  private boolean typeCheckLocal() {
    TypeNode fromType = expr.getType();
    if (fromType instanceof NodeTypeNode && type instanceof NodeTypeNode) {
      // we support up- and down-casts, but no cross-casts of nodes
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((NodeTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((NodeTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }
    if (fromType instanceof EdgeTypeNode && type instanceof EdgeTypeNode) {
      // we support up- and down-casts, but no cross-casts of edges
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((EdgeTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((EdgeTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }
    if (fromType instanceof ObjectTypeNode
        && !(type instanceof NodeTypeNode)
        && !(type instanceof EdgeTypeNode))
      return true; // object is castable to anything besides nodes and edges
    if (type instanceof ObjectTypeNode
        && !(fromType instanceof NodeTypeNode)
        && !(fromType instanceof EdgeTypeNode))
      return true; // anything besides nodes and edges can be casted into an object
    if (fromType instanceof ExternalTypeNode && type instanceof ExternalTypeNode) {
      // we support up- and down-casts, but no cross-casts of external types
      HashSet<TypeNode> supertypesOfFrom = new HashSet<TypeNode>();
      ((ExternalTypeNode) fromType).doGetCompatibleToTypes(supertypesOfFrom);
      HashSet<TypeNode> supertypesOfTo = new HashSet<TypeNode>();
      ((ExternalTypeNode) type).doGetCompatibleToTypes(supertypesOfTo);
      return fromType.equals(type)
          || supertypesOfFrom.contains(type)
          || supertypesOfTo.contains(fromType);
    }

    boolean result = fromType.isCastableTo(type);
    if (!result) {
      reportError("Illegal cast from \"" + expr.getType() + "\" to \"" + type + "\"");
    }

    return result;
  }
Exemplo n.º 9
0
  /** @see de.unika.ipd.grgen.ast.BaseNode#checkLocal() */
  @Override
  protected boolean checkLocal() {
    boolean res = true;
    TypeNode type = getType();
    int arity = OperatorSignature.getArity(opId);

    if (children.size() != arity) {
      reportError("Wrong operator arity: " + children.size());
      res = false;
    }

    // Here the error must have been already reported
    if (type.isEqual(BasicTypeNode.errorType)) res = false;

    return res;
  }
Exemplo n.º 10
0
  public Object constantValue() {
    Object v = expr.constantValue();

    if (v == null) {
      return null;
    }

    if (v instanceof Boolean) {
      if (castType.type().isBoolean()) return v;
    }

    if (v instanceof String) {
      TypeSystem ts = castType.type().typeSystem();
      if (castType.type().equals(ts.String())) return v;
    }

    if (v instanceof Double) {
      double vv = ((Double) v).doubleValue();

      if (castType.type().isDouble()) return new Double((double) vv);
      if (castType.type().isFloat()) return new Float((float) vv);
      if (castType.type().isLong()) return new Long((long) vv);
      if (castType.type().isInt()) return new Integer((int) vv);
      if (castType.type().isChar()) return new Character((char) vv);
      if (castType.type().isShort()) return new Short((short) vv);
      if (castType.type().isByte()) return new Byte((byte) vv);
    }

    if (v instanceof Float) {
      float vv = ((Float) v).floatValue();

      if (castType.type().isDouble()) return new Double((double) vv);
      if (castType.type().isFloat()) return new Float((float) vv);
      if (castType.type().isLong()) return new Long((long) vv);
      if (castType.type().isInt()) return new Integer((int) vv);
      if (castType.type().isChar()) return new Character((char) vv);
      if (castType.type().isShort()) return new Short((short) vv);
      if (castType.type().isByte()) return new Byte((byte) vv);
    }

    if (v instanceof Number) {
      long vv = ((Number) v).longValue();

      if (castType.type().isDouble()) return new Double((double) vv);
      if (castType.type().isFloat()) return new Float((float) vv);
      if (castType.type().isLong()) return new Long((long) vv);
      if (castType.type().isInt()) return new Integer((int) vv);
      if (castType.type().isChar()) return new Character((char) vv);
      if (castType.type().isShort()) return new Short((short) vv);
      if (castType.type().isByte()) return new Byte((byte) vv);
    }

    if (v instanceof Character) {
      char vv = ((Character) v).charValue();

      if (castType.type().isDouble()) return new Double((double) vv);
      if (castType.type().isFloat()) return new Float((float) vv);
      if (castType.type().isLong()) return new Long((long) vv);
      if (castType.type().isInt()) return new Integer((int) vv);
      if (castType.type().isChar()) return new Character((char) vv);
      if (castType.type().isShort()) return new Short((short) vv);
      if (castType.type().isByte()) return new Byte((byte) vv);
    }

    // not a constant
    return null;
  }
Exemplo n.º 11
0
 public boolean isConstant() {
   return expr.isConstant() && castType.type().isPrimitive();
 }
  protected void setUp() {
    //                d.on ();

    // Create a time manager to synchronize back tracking
    BTTimeManager timeMan = new BTTimeManager();

    // Create the symbol table
    rt_symtab = new RT_Symbol_Table(timeMan);

    // Create a virtual machine state .
    vms =
        new VMState(
            timeMan, boStatic, toStatic, boHeap, toHeap, boStack, toStack, boScratch, toScratch,
            rt_symtab);

    Cpp_StatementManager sm = new Cpp_StatementManager();
    if (dm == null) dm = new Cpp_DeclarationManager(cem, sm, vms);

    // Prepare the VMState
    vms.setProperty("ASTUtilities", new Cpp_ASTUtilities());
    vms.setProperty("DatumUtilities", new DatumUtilities());

    // create the expression for 5
    five = new ConstInt(ctyInt, "5", 5);

    // create the expression for 1
    one = new ConstInt(ctyInt, "1", 1);

    // create the expression for x
    String xid = "x";
    x_sn = new Cpp_ScopedName(xid);
    x = new ExpId(new TyRef(tyInt), xid, x_sn);

    // create the expression for 5.0
    ffive = new ConstFloat(ctyFloat, "5.0", 5.0);

    // create the expression for 1.0
    fone = new ConstFloat(ctyFloat, "1.0", 1.0);

    // create the expression for y
    String yid = "y";
    y_sn = new Cpp_ScopedName(yid);
    y = new ExpId(new TyRef(tyFloat), yid, y_sn);

    tyPointer = new TyPointer();
    tyPointer.addToEnd(tyInt);
    // create the expression for p
    String pid = "p";
    p = new ExpId(new TyRef(tyPointer), pid, new Cpp_ScopedName(pid));

    tyArray = new TyArray();
    tyArray.addToEnd(tyInt);
    // create the expression for a
    String aid = "a";
    a = new ExpId(new TyRef(tyArray), aid, new Cpp_ScopedName(aid));

    String idC = "C";
    sn_C = new Cpp_ScopedName(idC);
    tyClass = new TyClass(idC, sn_C, null);
    // create the expression for c
    String cid = "c";
    c_sn = new Cpp_ScopedName(cid);
    c = new ExpId(new TyRef(tyClass), cid, c_sn);

    String bid = "b";
    b = new ExpId(new TyRef(tyBool), bid, new Cpp_ScopedName(bid));

    _true = new ConstInt(tyBool, "true", 1);

    // create a string constant
    str_const = (ConstStr) Literals.make_string_const("\"blah\"", vms);
    // array of char
    tyArrayChar = new TyArray();
    tyArrayChar.addToEnd(tyChar);
    // create the expression for a
    String acid = "ac";
    ac = new ExpId(new TyRef(tyArrayChar), acid, new Cpp_ScopedName(acid));

    // reference to int
    tyRefInt = new TyRef(tyInt);

    // create the id expression for rint
    String riid = "ri";
    r_sn = new Cpp_ScopedName(riid);
    rint = new ExpId(new TyRef(tyRefInt), riid, r_sn);

    // constant reference to int
    ctyRefInt = new TyRef(ctyInt);
    ctyRefInt.setAttributes(Cpp_Specifiers.CVQ_CONST);

    // create the id expression for rint
    String criid = "cri";
    crint = new ExpId(new TyRef(ctyRefInt), criid, new Cpp_ScopedName(criid));

    // function taking no parameters and returning int
    tyFun = new TyFun(new Vector(), false);
    tyFun.addToEnd(tyInt);

    // create the following scope and declaration space
    // int x;
    // int &r;
    // int foo ();
    // class C {
    // 	float y;
    // 	int bar ();
    // };
    // C c;
    // C *pc;

    Cpp_SpecifierSet sps = new Cpp_SpecifierSet();
    NodeList nl = new NodeList();
    Declaration decl;

    // int x
    decl = new Declaration(VARIABLE_LF, x_sn, null, sps, tyInt);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyInt));
    st.addDeclaration(decl);

    // int &r
    decl = new Declaration(VARIABLE_LF, r_sn, null, sps, tyRefInt);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyRefInt));
    st.addDeclaration(decl);

    // int foo ()
    foo_sn = new Cpp_ScopedName("foo");
    st.addDefiningDeclaration(foo_sn, REG_FN_LF, tyFun);

    // class C
    ClassHead chc = new ClassHead(ClassHead.CLASS, sn_C, new Vector());
    Declaration c_decl = st.addDefiningDeclaration(chc);

    st.enterScope(c_decl);

    // float y
    decl = new Declaration(VARIABLE_LF, y_sn, null, sps, tyFloat);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyFloat));
    st.addDeclaration(decl);

    // int bar ()
    bar_sn = new Cpp_ScopedName("bar");
    st.addDefiningDeclaration(bar_sn, MEM_FN_LF, tyFun);

    st.exitScope();

    // C c
    decl = new Declaration(VARIABLE_LF, c_sn, null, sps, tyClass);
    decl.setDefinition(c_decl);
    decl.getCategory().set(dm.type_extractor.categorizeClass(decl));
    st.addDeclaration(decl);

    tyPointerClass = new TyPointer();
    tyPointerClass.addToEnd(tyClass);
    // C *pc
    String pcid = "pc";
    pc_sn = new Cpp_ScopedName(pcid);
    pc = new ExpId(new TyRef(tyPointer), pcid, pc_sn);
    decl = new Declaration(VARIABLE_LF, pc_sn, null, sps, tyPointerClass);
    decl.setDefinition(decl);
    decl.getCategory().set(dm.type_extractor.categorizeType(tyPointerClass));
    st.addDeclaration(decl);
  }
 void genJavaWrites(PrintWriter writer, int depth) {
   for (Iterator it = components.iterator(); it.hasNext(); ) {
     TypeNode tn = (TypeNode) it.next();
     tn.genJavaWrite(writer, depth, tn.name());
   }
 }