Ejemplo n.º 1
0
void 
Code_Project::reduce1() 
{
  Code_c::reduce1();

#ifdef ENABLE_PROJECT
  // ex x: phi --> phi[y/x] if phi = .. & x=y & .. where x!=y
  //                           and y already in all affected export-vars
  Ident y = findEquality(var, vc);
  vc.code->clearEqlist();
  if (y != -1 && !checkExport(var))
    y = -1; /* cancel */
  clearEqlist();
  if (y != -1) {
    invariant(y != var);
    IdentList formals(var), actuals(y);
    forwarded = vc.substCopy(&formals, &actuals);
    forwarded.reduce();
  }
  // ex x: phi --> phi if x notin FV(phi)
  else if (!vc.vars->exists(var)) {
    vc.code->refs++;
    forwarded = VarCode(vc.vars->copy(), vc.code);
  }
  if (forwarded.code)
    codeTable->red_proj++;
#endif
}
Ejemplo n.º 2
0
/* handle id, literals, and (...) */
static Expression *e1(void) {
  if (isLeft()) {
    /* ( <expression> ) */
    consume();
    Expression *e = expression();
    if (!isRight()) {
      error();
    }
    consume();
    return e;
  } else if (isInt()) {
    /* 123 */
    int v = getInt();
    consume();
    Expression *e = NEW(Expression);
    e->kind = eVAL;
    e->val = v;
    return e;
  } else if (isId()) {
    /* xyz */
    char *id = getId();
    consume();
    if (isLeft()) {
      /* xyz ( <actuals> ) */
      consume();

      Expression *e = NEW(Expression);

      e->kind = eCALL;

      e->callName = id;
      e->callActuals = actuals();

      if (!isRight())
        error();
      consume();

      return e;
    } else {
      Expression *e = NEW(Expression);
      e->kind = eVAR;
      e->varName = id;
      return e;
    }
  } else {
    error();
    return 0;
  }
}
Ejemplo n.º 3
0
/* [ <expression> [, <actuals> ]] */
static Actuals *actuals(void) {
  if (isRight())
    return 0;
  Actuals *p = NEW(Actuals);
  p->first = expression();
  p->rest = 0;
  p->n = 1;

  if (isComma()) {
    consume();
    p->rest = actuals();
    p->n = p->rest->n + 1;
  }

  return p;
}
Ejemplo n.º 4
0
void IRRewriter::visit(const CallStmt *op) {
  std::vector<Expr> actuals(op->actuals.size());
  bool actualsSame = true;
  for (size_t i=0; i < op->actuals.size(); ++i) {
    actuals[i] = rewrite(op->actuals[i]);
    if (actuals[i] != op->actuals[i]) {
      actualsSame = false;
    }
  }
  if (actualsSame) {
    stmt = op;
  }
  else {
    stmt = CallStmt::make(op->results, op->callee, actuals);
  }
}
Ejemplo n.º 5
0
void UmlClass::write_actuals(FileOut & out)
{
    Q3ValueList<UmlActualParameter> actual_params = actuals();
    Q3ValueList<UmlActualParameter>::ConstIterator iter;
    int rank;
    UmlClass * super = 0;

    for (iter = actual_params.begin(), rank = 0;
         iter != actual_params.end();
         ++iter, rank += 1) {
        if (super != (*iter).superClass()) {
            if (super != 0) {
                out.indent(-1);
                out.indent();
                out << "</templateBinding>\n";
            }

            super = (*iter).superClass();

            out.indent();
            out << "<templateBinding xmi:type=\"uml:TemplateBinding\"";
            out.id_prefix(this, "ACTUAL", rank);
            out << ">\n";
            out.indent(+1);

            out.indent();
            out << "<boundElement";
            out.idref(this);
            out << " />\n";

            out.indent();
            out << "<signature";
            out.idref_prefix(super, "FORMALS_");
            out << " />\n";
        }

        (*iter).write(out, this, rank);
    }

    if (super != 0) {
        out.indent(-1);
        out.indent();
        out << "</templateBinding>\n";
    }

}
Ejemplo n.º 6
0
/*==============================================================================
 * FUNCTION:	   NJMCDecoder::instantiate
 * OVERVIEW:	   Given an instruction name and a variable list of expressions representing the actual operands of
 *					the instruction, use the RTL template dictionary to return the instantiated RTL representing the
 *					semantics of the instruction.
 * PARAMETERS:	   pc: native PC
 *				   name - instruction name
 *				   ... - Semantic String ptrs representing actual operands
 * RETURNS:		   an instantiated list of Exps
 *============================================================================*/
std::list<Statement*>* NJMCDecoder::instantiate(ADDRESS pc, const char* name, ...)
{
    // Get the signature of the instruction and extract its parts
    std::pair<std::string,unsigned> sig = RTLDict.getSignature(name);
    std::string opcode = sig.first;
    unsigned numOperands = sig.second;

    // Put the operands into a vector
    std::vector<Exp*> actuals(numOperands);
    va_list args;
    va_start(args,name);
    for (unsigned i = 0; i < numOperands; i++)
        actuals[i] = va_arg(args,Exp*);
    va_end(args);

    if (DEBUG_DECODER)
        {
            // Display a disassembly of this instruction if requested
            std::cout << std::hex << pc << std::dec << ": " << name << " ";
            for (std::vector<Exp*>::iterator itd = actuals.begin(); itd != actuals.end(); itd++)
                {
                    if ((*itd)->isIntConst())
                        {
                            int val = ((Const*)(*itd))->getInt();
                            if (val > 100 || val < -100)
                                std::cout << std::hex << "0x" << val << std::dec;
                            else
                                std::cout << val;
                        }
                    else
                        (*itd)->print(std::cout);
                    if (itd != actuals.end()-1)
                        std::cout << ", ";
                }
            std::cout << std::endl;
        }

    std::list<Statement*>* instance = RTLDict.instantiateRTL(opcode, pc, actuals);

    return instance;
}
Ejemplo n.º 7
0
void UmlClass::gen_java_decl(QCString s, bool descr) {
  const char * p = bypass_comment(s);
  UmlRelation * extend = 0;

  while (*p != 0) {
    if (!strncmp(p, "${comment}", 10))
      p += 10;
    else if (!strncmp(p, "${description}", 14))
      p += 14;
    else if (!strncmp(p, "${public}", 9)) {
      p += 9;
      if (isJavaPublic())
	fw.write("public ");
    }
    else if (!strncmp(p, "${visibility}", 13)) {
      p += 13;
      UmlItem::write(visibility(), javaLanguage);
      fw.write(' ');
    }
    else if (!strncmp(p, "${final}", 8)) {
      p += 8;
      if (isJavaFinal())
	fw.write("final ");
    }
    else if (!strncmp(p, "${abstract}", 11)) {
      p += 11;
      if (isAbstract())
	fw.write("abstract ");
    }
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      writeq(name());
      generics();
    }
    else if (!strncmp(p, "${extends}", 10)) {
      p += 10;

      const QVector<UmlItem> ch = children();

      for (unsigned i = 0; i != ch.size(); i += 1) {
	if (ch[i]->kind() == aRelation) {
	  UmlRelation * rel = (UmlRelation *) ch[i];
	  aRelationKind k = rel->relationKind();
	  
	  if (((k == aGeneralisation) ||
	       (k == aRealization)) &&
	      (!rel->javaDecl().isEmpty()) &&
	      ((JavaSettings::classStereotype(stereotype()) == "interface") ||
	       (JavaSettings::classStereotype(rel->roleType()->stereotype()) != "interface"))) {
	    extend = rel;
	    fw.write(" extends ");
	    rel->roleType()->write();
	    generate(actuals(), rel->roleType(), FALSE);
	    break;
	  }
	}
      }
    }
    else if (!strncmp(p, "${implements}", 13)) {
      p += 13;

      const QVector<UmlItem> ch = children();
      const char * sep = " implements ";

      for (unsigned i = 0; i != ch.size(); i += 1) {
	if (ch[i]->kind() == aRelation) {
	  UmlRelation * rel = (UmlRelation *) ch[i];
	  aRelationKind k = rel->relationKind();
	  
	  if ((rel != extend) &&
	      ((k == aGeneralisation) ||
	       (k == aRealization)) &&
	      (!rel->javaDecl().isEmpty())) {
	    fw.write(sep);
	    sep = ", ";
	    rel->roleType()->write();
	    generate(actuals(), rel->roleType(), FALSE);
	  }
	}
      }
    }
    else if (!strncmp(p, "${@}", 4))
      p += 4;
    else if (*p == '\r')
      p += 1;
    else if (*p == '\n') {
      if (descr) {
	fw.write("<br />");
	p += 1;
      }
      else {
	fw.write(' ');
	
	do
	  p += 1;
	while ((*p != 0) && (*p <= ' '));
      }
    }
    else if ((*p == '{') || (*p == ';')) {
      if (descr)
	fw.write(*p++);
      else
	break;
    }
    else if (*p == '@')
      manage_alias(p);
    else
      writeq(*p++);
  }
}
Ejemplo n.º 8
0
void UmlClass::gen_cpp_decl(QCString s, bool descr) {
  const char * p = (descr)
    ? (const char *) s
    : (const char *) bypass_comment(s);

  while (*p) {
    if (!strncmp(p, "${comment}", 10))
      p += 10;
    else if (!strncmp(p, "${description}", 14))
      p += 14;
    else if (!strncmp(p, "${type}", 7)) {
      p += 7;
      bool find = FALSE;

      if (baseType().type != 0) {
	UmlClass * mother = baseType().type;
	const QVector<UmlItem> ch = children();
	
	for (unsigned i = 0; i != ch.size(); i += 1) {
	  if (ch[i]->kind() == aRelation) {
	    UmlRelation * rel = (UmlRelation *) ch[i];
	    aRelationKind k = rel->relationKind();
	    
	    if (((k == aGeneralisation) ||
		 (k == aRealization)) &&
		(rel->roleType() == mother)) {
	      rel->roleType()->write();
	      generate(actuals(), mother, TRUE);
	      find = TRUE;
	      break;
	    }
	  }
	}
      }
      if (! find)
	UmlItem::write(baseType(), cppLanguage);
    }
    else if (!strncmp(p, "${template}", 11)) {
      p += 11;
      generate(formals());
    }
    else if (!strncmp(p, "${name}", 7)) {
      p += 7;
      writeq(name());
    }
    else if (!strncmp(p, "${inherit}", 10)) {
      p += 10;

      const QVector<UmlItem> ch = children();
      const char * sep = " : ";

      for (unsigned i = 0; i != ch.size(); i += 1) {
	if (ch[i]->kind() == aRelation) {
	  UmlRelation * rel = (UmlRelation *) ch[i];
	  aRelationKind k = rel->relationKind();
	  
	  if (((k == aGeneralisation) ||
	       (k == aRealization)) &&
	      !rel->cppDecl().isEmpty()) {
	    fw.write(sep);
	    // UmlItem::write else G++ call UmlClass::write(QCString) !
	    UmlItem::write((rel->cppVisibility() == DefaultVisibility)
		           ? rel->visibility() : rel->cppVisibility(),
			   cppLanguage);
	    fw.write((rel->cppVirtualInheritance()) ? " virtual " : " ");
	    rel->roleType()->write();
	    generate(actuals(), rel->roleType(), TRUE);
	    sep = ", ";
	  }
	}
      }
    }
    else if (*p == '{') {
      if (descr)
	fw.write(*p++);
      else
	break;
    }
    else if (*p == '\r')
      p += 1;
    else if (*p == '\n') {
      if (descr) {
	fw.write("<br />");
	p += 1;
      }
      else {
	fw.write(' ');
	
	do
	  p += 1;
	while ((*p != 0) && (*p <= ' '));
      }
    }
    else if (*p == '@')
      manage_alias(p);
    else
      writeq(*p++);
  }

}