Expose more logic from BuildCache.

This commit is contained in:
Juraj Kirchheim
2017-12-18 11:27:32 +01:00
parent bfc5c2b88f
commit ff9ef59445

View File

@@ -106,23 +106,30 @@ class BuildCache {
})); }));
} }
static public function getParam(name:String, ?pos:Position) static public function getParams(name:String, ?pos:Position)
return return
switch Context.getLocalType() { switch Context.getLocalType() {
case TInst(_.toString() == name => true, [v]): case TInst(_.toString() == name => true, v):
v; Success(v);
case TInst(_.toString() == name => true, _):
pos.error('type parameter expected');
case TInst(_.get() => { pos: pos }, _): case TInst(_.get() => { pos: pos }, _):
pos.error('Expected $name'); pos.makeFailure('Expected $name');
default: case v:
throw 'assert'; pos.makeFailure('$v should be a class');
} }
static public function getParam(name:String, ?pos:Position)
return
getParams(name, pos)
.flatMap(function (args:Array<Type>) return switch args {
case [v]: Success(v);
case []: pos.makeFailure('type parameter expected');
default: pos.makeFailure('too many parameters');
});
static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) { static public function getType(name, ?type, ?pos:Position, build:BuildContext->TypeDefinition) {
if (type == null) if (type == null)
type = getParam(name, pos); type = getParam(name, pos).sure();
var forName = var forName =
switch cache[name] { switch cache[name] {