コード例 #1
0
/*
 * Check and cast arguments for builtins.
 */
static int
acnt(NODE *a, int narg, TWORD *tp)
{
    NODE *q;
    TWORD t;

    if (a == NIL)
        return narg;
    for (; a->n_op == CM; a = a->n_left, narg--) {
        if (tp == NULL)
            continue;
        q = a->n_right;
        t = ctype(tp[narg-1]);
        if (q->n_type == t)
            continue;
        a->n_right = ccast(q, t, 0, NULL, 0);
    }

    /* Last arg is ugly to deal with */
    if (narg == 1 && tp != NULL && a->n_type != tp[0]) {
        q = talloc();
        *q = *a;
        q = ccast(q, ctype(tp[0]), 0, NULL, 0);
        *a = *q;
        nfree(q);
    }
    return narg != 1;
}
コード例 #2
0
ファイル: casts.cpp プロジェクト: neingeist/cpp-exercises
int main() {
  myclass a("a");
  mybase base("base");

  std::cout << "== nocast" << std::endl;
  nocast(&a);
  // nocast(&base); <- Does not compile

  std::cout << "== ccast" << std::endl;
  ccast(&a);
  ccast(&base);  // XXX actually works!

  std::cout << "== staticcast" << std::endl;
  staticcast(&a);
  staticcast(&base);  // XXX actually works!

  std::cout << "== dynamiccast" << std::endl;
  dynamiccast(&a);
  dynamiccast(&base);
}
コード例 #3
0
ファイル: code.c プロジェクト: ajinkya93/netbsd-src
static void
addreg(NODE *p)
{
	TWORD t;
	NODE *q;
	int sz, r;

	sz = tsize(p->n_type, p->n_df, p->n_ap)/SZCHAR;
	sz = (sz + 3) >> 2;	/* sz in regs */
	if ((regcvt+sz) > rparg) {
		regcvt = rparg;
		return;
	}
	if (sz > 2)
		uerror("cannot put struct in 3 regs (yet)");

	if (sz == 2)
		r = regcvt == 0 ? AXDX : DXCX;
	else
		r = regcvt == 0 ? AX : regcvt == 1 ? DX : CX;

	if (p->n_op == FUNARG) {
		/* at most 2 regs */
		if (p->n_type < INT) {
			p->n_left = ccast(p->n_left, INT, 0, 0, 0);
			p->n_type = INT;
		}

		p->n_op = ASSIGN;
		p->n_right = p->n_left;
	} else if (p->n_op == STARG) {
		/* convert to ptr, put in reg */
		q = p->n_left;
		t = sz == 2 ? LONGLONG : INT;
		q = cast(q, INCREF(t), 0);
		q = buildtree(UMUL, q, NIL);
		p->n_op = ASSIGN;
		p->n_type = t;
		p->n_right = q;
	} else
		cerror("addreg");
	p->n_left = block(REG, 0, 0, p->n_type, 0, 0);
	regno(p->n_left) = r;
	regcvt += sz;
}
コード例 #4
0
ファイル: code.c プロジェクト: fhector/helenOS-0.5-Hector
NODE *
amd64_builtin_va_arg(NODE *f, NODE *a, TWORD t)
{
	NODE *ap, *r, *dp;

	ap = a->n_left;
	dp = a->n_right;
	if (dp->n_type <= ULONGLONG || ISPTR(dp->n_type) ||
	    dp->n_type == FLOAT || dp->n_type == DOUBLE) {
		/* type might be in general register */
		if (dp->n_type == FLOAT || dp->n_type == DOUBLE) {
			f->n_sp = lookup(fpnext, SNORMAL);
			varneeds |= NEED_FPNEXT;
		} else {
			f->n_sp = lookup(gpnext, SNORMAL);
			varneeds |= NEED_GPNEXT;
		}
		f->n_type = f->n_sp->stype = INCREF(dp->n_type) + (FTN-PTR);
		f->n_ap = dp->n_ap;
		f->n_df = /* dp->n_df */ NULL;
		f = clocal(f);
		r = buildtree(CALL, f, ccopy(ap));
	} else if (ISSOU(dp->n_type) || dp->n_type == LDOUBLE) {
		/* put a reference directly to the stack */
		int sz = tsize(dp->n_type, dp->n_df, dp->n_ap);
		int al = talign(dp->n_type, dp->n_ap);
		if (al < ALLONG)
			al = ALLONG;
		if (sz <= SZLONG*2 && al == ALLONG) {
			if (sz <= SZLONG) {
				f->n_sp = lookup(_1regref, SNORMAL);
				varneeds |= NEED_1REGREF;
			} else {
				f->n_sp = lookup(_2regref, SNORMAL);
				varneeds |= NEED_2REGREF;
			}
			f->n_type = f->n_sp->stype;
			f = clocal(f);
			r = buildtree(CALL, f, ccopy(ap));
			r = ccast(r, INCREF(dp->n_type), 0, dp->n_df, dp->n_ap);
			r = buildtree(UMUL, r, NIL);
		} else {
			f->n_sp = lookup(memref, SNORMAL);
			varneeds |= NEED_MEMREF;
			f->n_type = f->n_sp->stype;
			f = clocal(f);
			SETOFF(sz, al);
			r = buildtree(CALL, f,
			    buildtree(CM, ccopy(ap), bcon(sz/SZCHAR)));
			r = ccast(r, INCREF(dp->n_type), 0, dp->n_df, dp->n_ap);
			r = buildtree(UMUL, r, NIL);
		}
	} else {
		uerror("amd64_builtin_va_arg not supported type");
		goto bad;
	}
	tfree(a);
	return r;
bad:
	uerror("bad argument to __builtin_va_arg");
	return bcon(0);
}
コード例 #5
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual double Run(CVectorBratAlgorithmParam& args) override
 {
     double result;
     return processCall( PyObject_CallMethod( m_instance, ccast( "Run" ),ccast( "(O)"), createPyArguments( args ) ), result );
 }
コード例 #6
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual std::string GetOutputUnit() const override
 {
     std::string result;
     return processCall( PyObject_CallMethod( m_instance, ccast( "GetOutputUnit" ), nullptr ), result );
 }
コード例 #7
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual std::string GetInputParamUnit(uint32_t indexParam) const override
 {
     std::string result;
     return processCall( PyObject_CallMethod( m_instance, ccast( "GetInputParamUnit" ), ccast( "(i)" ), indexParam ), result );
 }
コード例 #8
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual CBratAlgorithmParam::bratAlgoParamTypeVal GetInputParamFormat(uint32_t indexParam) const override
 {
     uint32_t result;
     return (CBratAlgorithmParam::bratAlgoParamTypeVal)
             processCall( PyObject_CallMethod( m_instance, ccast( "GetInputParamFormat" ), ccast( "(i)" ), indexParam ), result );
 }
コード例 #9
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual uint32_t GetNumInputParam() const override
 {
     uint32_t result;
     return processCall( PyObject_CallMethod( m_instance, ccast( "GetNumInputParam" ), nullptr ), result );
 }
コード例 #10
0
ファイル: PythonEngine.hpp プロジェクト: BRAT-DEV/main
 virtual std::string GetDescription() const override
 {
     std::string result;
     return processCall( PyObject_CallMethod( m_instance, ccast( "GetDescription" ), nullptr ), result );
 }