@@ -313,6 +313,8 @@ uniontype Call
313313 algorithm
314314
315315 (call, ty, variability) := match callExp
316+ case Expression . CALL (UNTYPED_CALL (ref= ComponentRef . CREF (node= InstNode . CLASS_NODE (name= "pre" ))))
317+ then typePreCall(callExp. call, info);
316318 case Expression . CALL (UNTYPED_CALL ()) then typeNormalCall(callExp. call, info);
317319 case Expression . CALL (UNTYPED_MAP_CALL ()) then typeMapIteratorCall(callExp. call, info);
318320 end match;
@@ -408,7 +410,7 @@ uniontype Call
408410
409411 // Type the arguments.
410412 argtycall := typeArgs(call,info);
411- // Match the arguments with the expeted ones.
413+ // Match the arguments with the expected ones.
412414 (fn,tyArgs) := matchFunctions(argtycall,info);
413415
414416 args := list(Util . tuple31(a) for a in tyArgs);
@@ -440,6 +442,80 @@ uniontype Call
440442 end match;
441443 end typeNormalCall;
442444
445+ function typePreCall
446+ input output Call call;
447+ input SourceInfo info;
448+ output Type ty;
449+ output Variability variability;
450+ protected
451+ Call argtycall;
452+ InstNode fn_node;
453+ list< Function > fnl;
454+ Boolean fn_typed, special;
455+ Function fn;
456+ Expression e;
457+ list< Type > arg_ty;
458+ list< Variability > arg_var;
459+ CallAttributes ca;
460+ list< TypedArg > tyArgs;
461+ list< TypedNamedArg > nargs;
462+ algorithm
463+ (call , ty, variability) := match call
464+ case UNTYPED_CALL (ref = ComponentRef . CREF (node = fn_node))
465+ algorithm
466+ // Fetch the cached function(s).
467+ CachedData . FUNCTION ({fn}, fn_typed, special) := InstNode . getFuncCache(fn_node);
468+
469+ // Type the function(s) if not already done.
470+ if not fn_typed then
471+ fn := Function . typeFunction(fn);
472+ InstNode . setFuncCache(fn_node, CachedData . FUNCTION ({fn}, true , special));
473+ end if ;
474+
475+ // Type the arguments.
476+ ARG_TYPED_CALL (arguments= tyArgs, named_args= nargs) := typeArgs(call,info);
477+ if not listEmpty(nargs) or listLength(tyArgs) <> 1 then
478+ Error . addSourceMessage(Error . NO_MATCHING_FUNCTION_FOUND , {toString(call), "<REMOVE ME>" , "pre(<T>) => <T>" }, info);
479+ end if ;
480+
481+ {(e,ty,variability)} := tyArgs;
482+
483+ _ := match e
484+ case Expression . CREF () then ();
485+ else
486+ algorithm
487+ Error . addSourceMessage(Error . NO_MATCHING_FUNCTION_FOUND , {toString(call), "<REMOVE ME>" , "pre(variable) => <T>" }, info);
488+ then fail();
489+ end match;
490+
491+ // TODO: Allow record components? Arrays?
492+ if not Type . isBasic(ty) then
493+ Error . addSourceMessage(Error . NO_MATCHING_FUNCTION_FOUND , {toString(call), "<REMOVE ME>" , "pre(basicType)" }, info);
494+ fail();
495+ end if ;
496+
497+ // TODO: Check if we are in function context?
498+
499+ ca := CallAttributes . CALL_ATTR (
500+ ty,
501+ Type . isTuple(ty),
502+ Function . isBuiltin(fn),
503+ Function . isImpure(fn),
504+ Function . isFunctionPointer(fn),
505+ Function . inlineBuiltin(fn),
506+ DAE . NO_TAIL ());
507+
508+ then
509+ (TYPED_CALL (fn, {e}, ca), ty, variability);
510+
511+ else
512+ algorithm
513+ assert (false , getInstanceName() + " got invalid function call expression" );
514+ then
515+ fail();
516+ end match;
517+ end typePreCall;
518+
443519 function typeArgs
444520 input output Call call;
445521 input SourceInfo info;
0 commit comments