Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 38bf65a

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
[NF] Type-check pre operator
Belonging to [master]: - #2009
1 parent c536259 commit 38bf65a

File tree

4 files changed

+95
-2
lines changed

4 files changed

+95
-2
lines changed

Compiler/NFFrontEnd/NFCall.mo

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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;

Compiler/NFFrontEnd/NFFunction.mo

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,7 @@ uniontype Function
704704
else
705705
special := match fn.path
706706
case Absyn.IDENT(name = "size") then true;
707+
case Absyn.IDENT(name = "pre") then true;
707708
else false;
708709
end match;
709710
end if;

Compiler/NFFrontEnd/NFType.mo

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,22 @@ public
259259
end match;
260260
end isScalarArray;
261261

262+
function isBasic
263+
input Type ty;
264+
output Boolean isNumeric;
265+
algorithm
266+
isNumeric := match ty
267+
case REAL() then true;
268+
case INTEGER() then true;
269+
case BOOLEAN() then true;
270+
case STRING() then true;
271+
case ENUMERATION() then true;
272+
case CLOCK() then true;
273+
case FUNCTION() then isBasic(ty.resultType);
274+
else false;
275+
end match;
276+
end isBasic;
277+
262278
function isBasicNumeric
263279
input Type ty;
264280
output Boolean isNumeric;

Compiler/NFFrontEnd/NFTypeCheck.mo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ algorithm
772772
{N2,M} := Type.arrayDims(inType2);
773773
if (not isValidMatrixMultiplyDims(N1,N2)) then
774774
binaryArrayOpError(inExp1,inType1,inExp2,inType2,inOp,
775-
"\n: Dimensions error in Vecto Matrix multiplication.");
775+
"\n: Dimensions error in Vector Matrix multiplication.");
776776
fail();
777777
else
778778
ty1 := Type.elementType(inType1);

0 commit comments

Comments
 (0)