示例#1
0
void do_function(FunctionType fn)
{
    if(DEBUG)	cout<<"function name : "<< fn.name() <<endl;

    statistics stats( fn.statistics() );
    for_each(stats.target().begin() , stats.target().end() , do_target);
}
示例#2
0
void
SemanticAnalysis::visitCallExpr(CallExpr *node)
{
#if 0
  HIR *callee = rvalue(node->callee());
  if (!callee)
    return;

  if (!callee->type()->isFunction()) {
    cc_.reportError(node->loc(), Message_CalleeNotFunction);
    return;
  }

  FunctionType *fun = callee->type()->toFunction();
  
  if (!checkArgumentCount(fun, node->arguments()->length())) {
    cc_.reportError(node->loc(), Message_ArgumentCountMismatch);
    return;
  }

  if (fun->isForward()) {
    cc_.reportError(node->loc(), Message_ForwardNotImplemented, fun->name()->chars());
    return;
  }

  HIRList *args = new (pool_) HIRList;
  for (unsigned i = 0; i < node->arguments()->length(); i++) {
    Expression *expression = node->arguments()->at(i);

    Type *actual = nullptr;
    bool needs_reference = false;
    if (i >= fun->parameters()->length()) {
      assert(fun->isNative() && fun->isNativeVariadic());
      needs_reference = true;
    } else {
      actual = fun->parameterAt(i);
      needs_reference = actual->isReference() || actual->isArray();
    }

    HIR *hir = nullptr;
    if (!needs_reference) {
      if ((hir = rvalue(expression)) == nullptr)
        return;
      if ((hir = coerce(hir, actual, Coerce_Arg)) == nullptr)
        return;
    } else {
      SValue arg;
      if (!svalue(expression, &arg))
        return;

      // :TODO:
      assert(!arg.isRValue());

      if (arg.isLValue()) {
        const LValue &lval = arg.lvalue();
        if (actual && actual->isReference() && lval.isBaseIndex()) {
          // Disabled - this feature is dangerous.
          cc_.reportError(expression->loc(), Message_CannotComputeIndexRef);
          return;
        }
        // :TODO: need to type check.
        hir = new (pool_) HAddressOf(expression, lval);
      }
    }

    args->append(hir);
  }

  hir_ = new (pool_) HCall(node, fun->returnType(), callee, args);
#endif
}