Beispiel #1
0
Box* sliceRepr(BoxedSlice* self) {
    BoxedString* start = static_cast<BoxedString*>(repr(self->start));
    BoxedString* stop = static_cast<BoxedString*>(repr(self->stop));
    BoxedString* step = static_cast<BoxedString*>(repr(self->step));
    std::string s = "slice(" + start->s + ", " + stop->s + ", " + step->s + ")";
    return new BoxedString(s);
}
Beispiel #2
0
 std::string toString()
 {
   std::string repr(sub_ ? "SUB\n" : "FUNCTION\n");
   for(unsigned int i = 0; i < body_.size(); i++)
     repr += "  " + body_[i]->toString() + "\n";
   return repr;
 }
Beispiel #3
0
QDataStream &operator<<(QDataStream& out, const PyObjectWrapper& myObj)
{
    if (Py_IsInitialized() == 0) {
        qWarning() << "Stream operator for PyObject called without python interpreter.";
        return out;
    }

    static PyObject *reduce_func  = 0;

    Shiboken::GilState gil;
    if (!reduce_func) {
        Shiboken::AutoDecRef pickleModule(PyImport_ImportModule("pickle"));
        reduce_func = PyObject_GetAttrString(pickleModule, "dumps");
    }
    Shiboken::AutoDecRef repr(PyObject_CallFunctionObjArgs(reduce_func, (PyObject*)myObj, NULL));
    if (repr.object()) {
        const char* buff = 0;
        Py_ssize_t size  = 0;
        if (PyBytes_Check(repr.object())) {
            buff = PyBytes_AS_STRING(repr.object());
            size = PyBytes_GET_SIZE(repr.object());
        } else if (Shiboken::String::check(repr.object())) {
            buff = Shiboken::String::toCString(repr.object());
            size = Shiboken::String::len(repr.object());
        }
        QByteArray data(buff, size);
        out << data;
    }
    return out;
}
Beispiel #4
0
TEST(Unsigned_Big_Numbers, addition_operator_test) {
  const lw_big::UBignum a{9223372036854775807};
  const lw_big::UBignum b{"9223372036852678655"};
  const std::string ans{"18446744073707454462"};
  const auto c = a + b;

  EXPECT_EQ(ans, c.repr(lw_big::base::dec));
}
Beispiel #5
0
TEST(Unsigned_Big_Numbers, addition_and_substraction_test1) {
  const lw_big::UBignum a{255};
  const lw_big::UBignum b{256};
  const lw_big::UBignum c{1};
  const auto res = a - b + c;
  const std::string ans{"65536"};
  EXPECT_EQ(ans, res.repr(lw_big::base::dec));
}
//----------------------------------------------------------------//
STLString MOAILayerBridge2D::ToString () {

	STLString repr( MOAITransform::ToString () );

	PRETTY_PRINT ( repr, mSourceScene )
	PRETTY_PRINT ( repr, mTargetScene )

	return repr;
}
static PyObject *StrokeAttribute_repr(BPy_StrokeAttribute *self)
{
	stringstream repr("StrokeAttribute:");
	repr << " r: " << self->sa->getColorR() << " g: " << self->sa->getColorG() << " b: " << self->sa->getColorB() <<
	        " a: " << self->sa->getAlpha() <<
	        " - R: " << self->sa->getThicknessR()  << " L: " << self->sa->getThicknessL();

	return PyUnicode_FromString(repr.str().c_str());
}
Beispiel #8
0
void export_candidatepoint(){
    py::class_<CandidatePoint, py::bases<Point> >("CandidatePoint", py::no_init)
        .def_readonly("belong", &CandidatePoint::belong, "belong which road")
        .def("distance_from_begin", &CandidatePoint::distance_from_begin, "the gis distance from begin follow road")
        .def_readonly("where", &CandidatePoint::where)
        .def(py::self == py::self)
        .def(py::self != py::self)
        .def(str(py::self))
        .def(repr(py::self));
}
Beispiel #9
0
int test_repr()
{
	zstr z2;
	czstr z = cs_as_cz("k");
	zstr rz = repr(z);
	#ifndef NDEBUG
	const czstr a = cs_as_cz("\\\\k");
	#endif

	assert (!strcmp((const char*)rz.buf, "k"));

	z = cs_as_cz("\\k");
	assert (z.len == 2);
	free_z(rz);
	rz = repr(z);
	assert (rz.len == 3);
	assert (a.len == 3);
	assert (!strcmp((const char*)rz.buf, "\\\\k"));
	assert (zeq(cz(rz), a));

	z2 = new_z(4);
	z2.buf[0] = 1;
	z2.buf[1] = 10;
	z2.buf[2] = 100;
	z2.buf[3] = 252;

	free_z(rz);
	rz = repr(cz(z2));
	assert (!strcmp((const char*)rz.buf, "\\x01\\x0ad\\xfc"));

	free_z(z2);
	z2 = new_z(1);
	z2.buf[0] = '\0';

	free_z(rz);
	rz = repr(cz(z2));
	assert (!strcmp((const char*)rz.buf, "\\x00"));

	free_z(z2);
	free_z(rz);
	return 0;
}
Beispiel #10
0
Box* dictGetitem(BoxedDict* self, Box* k) {
    Box* &pos = self->d[k];

    if (pos == NULL) {
        BoxedString *s = repr(k);
        fprintf(stderr, "KeyError: %s\n", s->s.c_str());
        raiseExc();
    }

    return pos;
}
Beispiel #11
0
Box* dictGetitem(BoxedDict* self, Box* k) {
    Box*& pos = self->d[k];

    if (pos == NULL) {
        BoxedString* s = static_cast<BoxedString*>(repr(k));
        fprintf(stderr, "KeyError: %s\n", s->s.c_str());
        raiseExcHelper(KeyError, "");
    }

    return pos;
}
Beispiel #12
0
template<class T> str *tuple2<T, T>::__repr__() {
    str *r = new str("(");
    for(int i = 0; i<this->__len__();i++) {
        r->unit += repr(this->units[i])->unit;
        if(this->__len__() == 1 )
            r->unit += ",";
        if(i<this->__len__()-1)
            r->unit += ", ";
    }
    r->unit += ")";
    return r;
}
Beispiel #13
0
Box* dictRepr(BoxedDict* self) {
    std::vector<char> chars;
    chars.push_back('{');
    bool first = true;
    for (BoxedDict::PyDict::iterator it = self->d.begin(), end = self->d.end(); it != end; ++it) {
        if (!first) {
            chars.push_back(',');
            chars.push_back(' ');
        }
        first = false;

        BoxedString *k = repr(it->first);
        BoxedString *v = repr(it->second);
        chars.insert(chars.end(), k->s.begin(), k->s.end());
        chars.push_back(':');
        chars.push_back(' ');
        chars.insert(chars.end(), v->s.begin(), v->s.end());
    }
    chars.push_back('}');
    return boxString(std::string(chars.begin(), chars.end()));
}
Beispiel #14
0
Box* dictRepr(BoxedDict* self) {
    std::vector<char> chars;
    chars.push_back('{');
    bool first = true;
    for (const auto& p : self->d) {
        if (!first) {
            chars.push_back(',');
            chars.push_back(' ');
        }
        first = false;

        BoxedString* k = static_cast<BoxedString*>(repr(p.first));
        BoxedString* v = static_cast<BoxedString*>(repr(p.second));
        chars.insert(chars.end(), k->s.begin(), k->s.end());
        chars.push_back(':');
        chars.push_back(' ');
        chars.insert(chars.end(), v->s.begin(), v->s.end());
    }
    chars.push_back('}');
    return boxString(std::string(chars.begin(), chars.end()));
}
Beispiel #15
0
static void
Pattern_setup(Pattern *patterns, int patterns_sz) {
	int i;
	Pattern *regex;

	#ifdef DEBUG
		fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
	#endif

	if (!Pattern_patterns_initialized) {
		Pattern_initialize(patterns, patterns_sz);
	} else {
		for (i = 0; i < patterns_sz; i++) {
			regex = Pattern_regex(patterns[i].tok, patterns[i].expr);
			#ifdef DEBUG
			if (regex) {
				fprintf(stderr, "\tAdded regex pattern %s: %s\n", repr(regex->tok), repr(regex->expr));
			}
			#endif
		}
	}
}
Beispiel #16
0
void testInterp(const string& input, const string& expected)
{
    Stack<Value> result;
    Stack<Env*> globals;
    bool ok = CompileModule(input, globals, result);
    testTrue(ok);
    Stack<Block*> block(result.as<CodeObject>()->block());
    ok = interp->exec(block, result);
    if (!ok)
        cerr << "Error: " << result.asObject()->as<Exception>()->message() << endl;
    testTrue(ok);
    testEqual(repr(result.get()), expected);
}
ui_assoc_object::~ui_assoc_object()
{
#ifdef TRACE_ASSOC
	CString rep = repr();
	const char *szRep = rep;
	TRACE("Destroying association with %p and %s",this,szRep);
#endif
	Py_CLEAR(virtualInst);
//	virtuals.DeleteAll();
	if (assoc) {
		handleMgr.Assoc(assoc, 0);
		SetAssocInvalid();			// let child do whatever to detect
	}
}
Beispiel #18
0
static Box* setRepr(BoxedSet* self) {
    RELEASE_ASSERT(PyAnySet_Check(self), "");

    std::vector<char> chars;
    int status = Py_ReprEnter((PyObject*)self);

    if (status != 0) {
        if (status < 0)
            throwCAPIException();

        std::string ty = std::string(self->cls->tp_name);
        chars.insert(chars.end(), ty.begin(), ty.end());
        chars.push_back('(');
        chars.push_back('.');
        chars.push_back('.');
        chars.push_back('.');
        chars.push_back(')');

        return boxString(llvm::StringRef(&chars[0], chars.size()));
    }

    try {
        std::string ty = std::string(self->cls->tp_name);
        chars.insert(chars.end(), ty.begin(), ty.end());

        chars.push_back('(');
        chars.push_back('[');

        bool first = true;
        for (auto&& elt : self->s) {

            if (!first) {
                chars.push_back(',');
                chars.push_back(' ');
            }
            BoxedString* str = static_cast<BoxedString*>(repr(elt.value));
            AUTO_DECREF(str);
            chars.insert(chars.end(), str->s().begin(), str->s().end());

            first = false;
        }
        chars.push_back(']');
        chars.push_back(')');
    } catch (ExcInfo e) {
        Py_ReprLeave((PyObject*)self);
        throw e;
    }
    Py_ReprLeave((PyObject*)self);
    return boxString(llvm::StringRef(&chars[0], chars.size()));
}
Beispiel #19
0
static Box* _setRepr(BoxedSet* self, const char* type_name) {
    std::ostringstream os("");

    os << type_name << "([";
    bool first = true;
    for (Box* elt : self->s) {
        if (!first) {
            os << ", ";
        }
        os << static_cast<BoxedString*>(repr(elt))->s;
        first = false;
    }
    os << "])";
    return boxString(os.str());
}
Beispiel #20
0
//OptionChecker:
void OptionChecker::check(const Object & o) const
{
    for(List::const_iterator i = this->_options.begin(); i != this->_options.end(); ++i)
    {
        //std::cout << "??? *i==" << i->repr() << " of type " << i->class_name() << " matches o==" << o.repr() << " of type " << o.class_name() << " ? " << Bool(i->operator ==(o)) << std::endl;
        if(i->operator ==(o))
        {
            //std::cout << "*i==" << i->repr() << " of type " << i->class_name() << " matches o==" << o.repr() << " of type " << o.class_name() << std::endl;
            return;
        }
    }
    std::ostringstream os;
    os << o.class_name() << ' ' << repr(o) << " is not a valid option";
    throw ValueError(DEBUG_INFO, os.str());
}
/*
  test of the contains( posinauto, posinauto ) method.
*/
void TestPosInText2PosInAudio::test3(void) {

   PosInText2PosInAudio text2audio = {
        { {{ {1,2}, {3,4} },},  {1500, 1598} },
        { {{ {5,6}, {9,12} },},  {1750, 1790} },
        { {{ {15,16}, {19,112} },},  {1950, 1999} },
      };

   QCOMPARE( text2audio.contains(115, 120).repr(), QString("") );
   QCOMPARE( text2audio.contains(5, 6).repr() , QString("5-6+9-12") );
   // we sort the result in order to avoid to get "5-6+9-12/1-2+3-4" ...
   auto res = text2audio.contains(1, 12);
   res.sort();
   QCOMPARE( res.repr() , QString("1-2+3-4/5-6+9-12") );
}
Beispiel #22
0
Box* tupleRepr(BoxedTuple* t) {

    assert(isSubclass(t->cls, tuple_cls));
    int n;
    std::vector<char> chars;
    int status = Py_ReprEnter((PyObject*)t);
    n = t->size();
    if (n == 0) {
        chars.push_back('(');
        chars.push_back(')');
        return boxString(llvm::StringRef(&chars[0], chars.size()));
    }

    if (status != 0) {
        if (status < 0)
            throwCAPIException();
        chars.push_back('(');
        chars.push_back('.');
        chars.push_back('.');
        chars.push_back('.');
        chars.push_back(')');

        return boxString(llvm::StringRef(&chars[0], chars.size()));
    }

    try {
        chars.push_back('(');
        for (int i = 0; i < n; i++) {
            if (i) {
                chars.push_back(',');
                chars.push_back(' ');
            }
            BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
            chars.insert(chars.end(), elt_repr->s().begin(), elt_repr->s().end());
        }

        if (n == 1)
            chars.push_back(',');

        chars.push_back(')');
    } catch (ExcInfo e) {
        Py_ReprLeave((PyObject*)t);
        throw e;
    }
    Py_ReprLeave((PyObject*)t);

    return boxString(llvm::StringRef(&chars[0], chars.size()));
}
Beispiel #23
0
Box* listIndex(BoxedList* self, Box* elt) {
    LOCK_REGION(self->lock.asRead());

    int size = self->size;

    for (int i = 0; i < size; i++) {
        Box* e = self->elts->elts[i];
        Box* cmp = compareInternal(e, elt, AST_TYPE::Eq, NULL);
        bool b = nonzero(cmp);
        if (b)
            return boxInt(i);
    }

    BoxedString* tostr = static_cast<BoxedString*>(repr(elt));
    raiseExcHelper(ValueError, "%s is not in list", tostr->s.c_str());
}
Beispiel #24
0
extern "C" Box* listRepr(BoxedList* self) {
    LOCK_REGION(self->lock.asRead());

    // TODO highly inefficient with all the string copying
    std::ostringstream os;
    os << '[';
    for (int i = 0; i < self->size; i++) {
        if (i > 0)
            os << ", ";

        BoxedString* s = static_cast<BoxedString*>(repr(self->elts->elts[i]));
        os << s->s;
    }
    os << ']';
    return new BoxedString(os.str());
}
Beispiel #25
0
void export_points(){
    py::class_<Point>("Point")
        .def(py::init<double, double>())
        .def_readwrite("x", &Point::x, "x")
        .def_readwrite("y", &Point::y, "x")
        .def("dist_to_segment", &point_dist_to_sement)
        .def("gis_dist", &Point::gis_dist, "gis_dist(Point) compute the gis distance")
        .def(py::self == py::self)
        .def(py::self != py::self)
        .def(py::self += py::self)
        .def(py::self + py::self)
        .def(py::self -= py::self)
        .def(py::self - py::self)
        .def(py::self *= py::other<double>())
        .def(py::self * py::other<double>())
        .def(py::other<double>() * py::self)
        .def(str(py::self))
        .def(repr(py::self));
}
Beispiel #26
0
void testReplacement(const string& input,
                     const string& expected,
                     InstrCode initial,
                     InstrCode replacement,
                     InstrCode next1 = InstrCodeCount,
                     InstrCode next2 = InstrCodeCount)
{
    Stack<Value> result;
    Stack<Env*> globals;
    bool ok = CompileModule(input, globals, result);
    testTrue(ok);
    Stack<Block*> block(result.as<CodeObject>()->block());

    InstrThunk* instrp = block->findInstr(Instr_Lambda);
    assert(instrp);
    Instr* instr = instrp->data;
    assert(instr->code() == Instr_Lambda);
    LambdaInstr* lambda = static_cast<LambdaInstr*>(instr);
    instrp = lambda->block()->findInstr(initial);
    assert(instrp);

    ok = interp->exec(block, result);
    if (!ok)
        cerr << "Error: " << result.asObject()->as<Exception>()->message() << endl;
    testTrue(ok);
    testEqual(repr(result.get()), expected);

    instr = instrp->data;
    testEqual(instrName(instr->code()), instrName(replacement));

    if (next1 < InstrCodeCount) {
        instr = getNextInstr(instr);
        assert(instr);
        testEqual(instrName(instr->code()), instrName(next1));

        if (next2 < InstrCodeCount) {
            instr = getNextInstr(instr);
            assert(instr);
            testEqual(instrName(instr->code()), instrName(next2));
        }
    }
}
Beispiel #27
0
Box* tupleRepr(BoxedTuple* t) {
    assert(isSubclass(t->cls, tuple_cls));

    std::string O("");
    llvm::raw_string_ostream os(O);
    os << "(";

    int n = t->size();
    for (int i = 0; i < n; i++) {
        if (i)
            os << ", ";

        BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
        os << elt_repr->s();
    }
    if (n == 1)
        os << ",";
    os << ")";

    return boxString(os.str());
}
Beispiel #28
0
static int
Pattern_match(Pattern *regex, char *string, int string_sz, int start_at, Token *p_token) {
	int options = PCRE_ANCHORED | PCRE_UTF8;
	const char *errptr;
	int ret, erroffset, ovector[3];
        ovector[0] = ovector[1] = ovector[2] = 0;
	pcre *p_pattern = regex->pattern;

	#ifdef DEBUG
		fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
	#endif

	if (p_pattern == NULL) {
		#ifdef DEBUG
			fprintf(stderr, "\tpcre_compile %s\n", repr(regex->expr));
		#endif
		p_pattern = regex->pattern = pcre_compile(regex->expr, options, &errptr, &erroffset, NULL);
	}
	ret = pcre_exec(
		p_pattern,
		NULL,                  /* no extra data */
		string,
		string_sz,
		start_at,
		PCRE_ANCHORED,         /* default options */
		ovector,               /* output vector for substring information */
		3                      /* number of elements in the output vector */
	);
	if (ret >= 0) {
		if (p_token) {
			p_token->regex = regex;
			p_token->string = string + ovector[0];
			p_token->string_sz = ovector[1] - ovector[0];
		}
		return 1;
	}
	return 0;
}
Beispiel #29
0
Box* tupleRepr(BoxedTuple* t) {
    assert(isSubclass(t->cls, tuple_cls));

    int n;
    std::string O("");
    llvm::raw_string_ostream os(O);

    n = t->size();
    if (n == 0) {
        os << "()";
        return boxString(os.str());
    }

    int status = Py_ReprEnter((PyObject*)t);
    if (status != 0) {
        if (status < 0)
            return boxString(os.str());

        os << "(...)";
        return boxString(os.str());
    }

    os << "(";

    for (int i = 0; i < n; i++) {
        if (i)
            os << ", ";

        BoxedString* elt_repr = static_cast<BoxedString*>(repr(t->elts[i]));
        os << elt_repr->s();
    }
    if (n == 1)
        os << ",";
    os << ")";

    Py_ReprLeave((PyObject*)t);
    return boxString(os.str());
}
Beispiel #30
0
void TerminalControl_CHAR::t_io_flush()
{
    if( output_size == 0 )
    {
        return;
    }

#if DBG_DISPLAY
    if( dbg_flags&DBG_DISPLAY )
    {
        EmacsString repr( EmacsString::copy, output_buffer, output_size );
        _dbg_msg( FormatString("t_io_flush: '%r'") << repr );
    }
#endif

    // convert to utf-8
    int  utf8_length = length_unicode_to_utf8( output_size, output_buffer );
    unsigned char utf8_buffer[ utf8_length ];
    convert_unicode_to_utf8( output_size, output_buffer, utf8_buffer );

    write( output_channel, &utf8_buffer, utf8_length );

    output_size = 0;
}