Exemplo n.º 1
0
static void checkArgument(int argc, char **argv)
{
	if (!isArgumentCorrect(argc, argv)) {
		argumentError(stderr, argc, argv);
		exit(1);
	}
}
Exemplo n.º 2
0
void argumentIndexRangeError(unsigned int index,
                             const string &kind,
                             size_t value,
                             size_t maxValue)
{
    ostringstream sout;
    sout << kind << " " << value << " is out of range. ";
    sout << "it should be less than " << maxValue;
    argumentError(index, sout.str());
}
Exemplo n.º 3
0
void TextOutputStream::disconnectFromTextBuffer(AbstractTextBuffer& oldBuffer)
{
	int pos = connectedTextBuffers.firstIndexOf(&oldBuffer);
	if (pos != -1)
	{
		connectedTextBuffers.remove(pos);
	}
	else
	{
		argumentError(BUFFER_TO_DISCONNECT_NOT_FOUND);
	}
}
Exemplo n.º 4
0
void initializeRecordFields(RecordTypePtr t) {
    assert(!t->fieldsInitialized);
    t->fieldsInitialized = true;
    RecordPtr r = t->record;
    if (r->varParam.ptr())
        assert(t->params.size() >= r->params.size());
    else
        assert(t->params.size() == r->params.size());
    EnvPtr env = new Env(r->env);
    for (unsigned i = 0; i < r->params.size(); ++i)
        addLocal(env, r->params[i], t->params[i].ptr());
    if (r->varParam.ptr()) {
        MultiStaticPtr rest = new MultiStatic();
        for (unsigned i = r->params.size(); i < t->params.size(); ++i)
            rest->add(t->params[i]);
        addLocal(env, r->varParam, rest.ptr());
    }
    RecordBodyPtr body = r->body;
    if (body->isComputed) {
        LocationContext loc(body->location);
        AnalysisCachingDisabler disabler;
        MultiPValuePtr mpv = analyzeMulti(body->computed, env);
        vector<TypePtr> fieldInfoTypes;
        if ((mpv->size() == 1) &&
            (mpv->values[0]->type->typeKind == RECORD_TYPE) &&
            (((RecordType *)mpv->values[0]->type.ptr())->record.ptr() ==
             prelude_RecordWithProperties().ptr()))
        {
            const vector<ObjectPtr> &params =
                ((RecordType *)mpv->values[0]->type.ptr())->params;
            assert(params.size() == 2);
            if (params[0]->objKind != TYPE)
                argumentError(0, "expecting a tuple of properties");
            TypePtr param0 = (Type *)params[0].ptr();
            if (param0->typeKind != TUPLE_TYPE)
                argumentError(0, "expecting a tuple of properties");
            TupleTypePtr props = (TupleType *)param0.ptr();
            if (params[1]->objKind != TYPE)
                argumentError(1, "expecting a tuple of fields");
            TypePtr param1 = (Type *)params[1].ptr();
            if (param1->typeKind != TUPLE_TYPE)
                argumentError(1, "expecting a tuple of fields");
            TupleTypePtr fields = (TupleType *)param1.ptr();
            fieldInfoTypes = fields->elementTypes;
            setProperties(t.ptr(), props->elementTypes);
        }
        else {
            for (unsigned i = 0; i < mpv->size(); ++i)
                fieldInfoTypes.push_back(mpv->values[i]->type);
        }
        for (unsigned i = 0; i < fieldInfoTypes.size(); ++i) {
            TypePtr x = fieldInfoTypes[i];
            IdentifierPtr name;
            TypePtr type;
            if (!unpackField(x, name, type))
                argumentError(i, "each field should be a "
                              "tuple of (name,type)");
            t->fieldIndexMap[name->str] = i;
            t->fieldTypes.push_back(type);
            t->fieldNames.push_back(name);
        }
    }
    else {
        for (unsigned i = 0; i < body->fields.size(); ++i) {
            RecordField *x = body->fields[i].ptr();
            t->fieldIndexMap[x->name->str] = i;
            TypePtr ftype = evaluateType(x->type, env);
            t->fieldTypes.push_back(ftype);
            t->fieldNames.push_back(x->name);
        }
    }
}
Exemplo n.º 5
0
void argumentInvalidStaticObjectError(unsigned int index, ObjectPtr obj)
{
    ostringstream sout;
    sout << "invalid static object: " << obj;
    argumentError(index, sout.str());
}
Exemplo n.º 6
0
void argumentTypeError(unsigned int index,
                       TypePtr expectedType,
                       TypePtr receivedType) {
    argumentError(index, typeErrorMessage(expectedType, receivedType));
}
Exemplo n.º 7
0
void argumentTypeError(unsigned int index,
                       const string &expected,
                       TypePtr receivedType) {
    argumentError(index, typeErrorMessage(expected, receivedType));
}