1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include "stdafx.h"
#include "Param.h"
#include "Type.h"
namespace storm {
namespace bs {
NameParam::NameParam(SrcName *type, Str *name) : type(type), name(name) {}
NameParam::NameParam(SrcName *type, syntax::SStr *name) : type(type), name(name->v) {}
wostream &operator <<(wostream &to, NameParam p) {
StrBuf *b = new (p.name) StrBuf();
*b << p;
return to << b->toS();
}
void NameParam::toS(StrBuf *to) const {
*to << type << S(" ") << name;
}
NameParam nameless(SrcName *type) {
return NameParam(type, new (type) Str(S("")));
}
ValParam::ValParam(Value type, Str *name)
: name(name), t(type.type), ref(type.ref), thisPar(false) {}
ValParam::ValParam(Value type, syntax::SStr *name)
: name(name->v), t(type.type), ref(type.ref), thisPar(false) {}
ValParam::ValParam(Value type, Str *name, Bool thisParam)
: name(name), t(type.type), ref(type.ref), thisPar(thisParam) {}
wostream &operator <<(wostream &to, ValParam p) {
StrBuf *b = new (p.name) StrBuf();
*b << p;
return to << b->toS();
}
void ValParam::toS(StrBuf *to) const {
*to << type() << S(" ") << name;
if (thisParam())
*to << S(" (this param)");
}
ValParam thisParam(Type *me) {
return thisParam(new (me) Str(S("this")), me);
}
ValParam thisParam(Str *name, Type *me) {
return ValParam(thisPtr(me), name, true);
}
ValParam resolve(NameParam param, Scope scope) {
return ValParam(scope.value(param.type), param.name);
}
Array<ValParam> *resolve(Array<NameParam> *params, Scope scope) {
Array<ValParam> *res = new (params) Array<ValParam>();
res->reserve(params->count());
for (nat i = 0; i < params->count(); i++)
res->push(resolve(params->at(i), scope));
return res;
}
Array<ValParam> *resolve(Array<NameParam> *params, Type *me, Scope scope) {
Array<ValParam> *res = new (params) Array<ValParam>();
res->reserve(params->count() + 1);
res->push(thisParam(me));
for (nat i = 0; i < params->count(); i++)
res->push(resolve(params->at(i), scope));
return res;
}
Array<Value> *values(Array<ValParam> *params) {
Array<Value> *r = new (params) Array<Value>();
r->reserve(params->count());
for (nat i = 0; i < params->count(); i++)
r->push(params->at(i).type());
return r;
}
Array<ValParam> *merge(Array<Value> *val, Array<Str *> *names) {
if (val->count() != names->count()) {
WARNING(L"Non-equal size of values and parameters, ignoring some entries!");
}
Nat to = min(val->count(), names->count());
Array<ValParam> *r = new (val) Array<ValParam>();
for (nat i = 0; i < to; i++) {
r->push(ValParam(val->at(i), names->at(i)));
}
return r;
}
}
}
|