@@ -472,6 +472,13 @@ algorithm
472472 end for ;
473473 then
474474 ();
475+
476+ case Instance . PARTIAL_BUILTIN ()
477+ algorithm
478+ instance. modifier := Modifier . merge(modifier, instance. modifier);
479+ then
480+ ();
481+
475482 end match;
476483end applyModifier;
477484
@@ -524,8 +531,11 @@ algorithm
524531 array< Component > components;
525532 ClassTree . Tree scope;
526533 Integer comp_count, idx;
527- Modifier comp_mod;
534+ Modifier type_mod;
535+ list< Modifier > type_mods, inst_type_mods;
536+ Binding binding;
528537
538+ // A normal class.
529539 case InstNode . INST_NODE (instance = i as Instance . EXPANDED_CLASS (elements = scope))
530540 algorithm
531541 comp_count := arrayLength(i. components);
@@ -551,6 +561,38 @@ algorithm
551561 then
552562 ();
553563
564+ // A builtin type.
565+ case InstNode . INST_NODE (instance = i as Instance . PARTIAL_BUILTIN ())
566+ algorithm
567+ inst_type_mods := {};
568+ // Merge any outer modifiers on the class with the class' own modifier.
569+ type_mod := Modifier . merge(modifier, i. modifier);
570+
571+ // If the modifier isn't empty, instantiate it.
572+ if not Modifier . isEmpty(type_mod) then
573+ type_mods := Modifier . toList(type_mod);
574+
575+ // Instantiate the binding of each submodifier.
576+ for m in type_mods loop
577+ _ := match m
578+ case Modifier . MODIFIER ()
579+ algorithm
580+ (binding, tree) := instBinding(m. binding, tree);
581+ m. binding := binding;
582+ then
583+ ();
584+
585+ else ();
586+ end match;
587+
588+ inst_type_mods := m :: inst_type_mods;
589+ end for ;
590+ end if ;
591+
592+ node. instance := Instance . INSTANCED_BUILTIN (inst_type_mods);
593+ then
594+ ();
595+
554596 else ();
555597 end match;
556598end instClass;
@@ -564,27 +606,21 @@ protected
564606 Modifier comp_mod;
565607 Binding binding;
566608 DAE . Type ty;
609+ Component redecl_comp;
567610algorithm
568611 (component, tree) := match component
569- // case (Component.COMPONENT_DEF(),
570- // Modifier.REDECLARE(element = comp as SCode.COMPONENT()))
571- // algorithm
572- // tree := InstanceTree.setCurrentScope(tree, modifier.scope); // redeclare scope
573- // comp_mod := Modifier.create(comp.modifications, comp.name, modifier.scope);
574- // comp_mod := Modifier.merge(modifier, comp_mod);
575- // binding := Modifier.binding(comp_mod);
576- // (cls, tree) := instTypeSpec(comp.typeSpec, comp_mod, tree);
577- // ty := makeType(cls);
578- // then
579- // (Component.COMPONENT(comp.name, cls, ty, binding), tree);
612+ case Component . COMPONENT_DEF (modifier = comp_mod as Modifier . REDECLARE ())
613+ algorithm
614+ redecl_comp := Component . COMPONENT_DEF (comp_mod. element, Modifier . NOMOD (), comp_mod. scope);
615+ then
616+ instComponent(redecl_comp, tree);
580617
581618 case Component . COMPONENT_DEF (definition = comp as SCode . COMPONENT ())
582619 algorithm
583620 tree := InstanceTree . setCurrentScope(tree, component. scope);
584621 comp_mod := Modifier . create(comp. modifications, comp. name,
585622 ModifierScope . COMPONENT_SCOPE (comp. name), component. scope);
586623 comp_mod := Modifier . merge(component. modifier, comp_mod);
587- // comp_mod := Modifier.merge(modifier, comp_mod);
588624 binding := Modifier . binding(comp_mod);
589625 (cls, tree) := instTypeSpec(comp. typeSpec, comp_mod, comp. info, tree);
590626 ty := makeType(cls);
@@ -617,28 +653,66 @@ algorithm
617653 end match;
618654end instTypeSpec;
619655
656+ function instModifier
657+ input output Modifier modifier;
658+ input output InstanceTree tree;
659+ algorithm
660+
661+ end instModifier;
662+
620663function makeType
621664 input InstNode node;
622665 output DAE . Type ty;
623666algorithm
624667 ty := match node
668+ local
669+ list< Modifier > type_mods;
670+ list< DAE . Var > type_attr;
671+
625672 case InstNode . INST_NODE (instance = Instance . INSTANCED_CLASS ())
626673 then DAE . T_COMPLEX_DEFAULT ;
627674
628- case InstNode . INST_NODE (instance = Instance . PARTIAL_BUILTIN ())
675+ case InstNode . INST_NODE (instance = Instance . INSTANCED_BUILTIN (attributes = type_mods))
676+ algorithm
677+ type_attr := list(makeTypeAttribute(m) for m in type_mods);
629678 then
630679 match node. name
631- case "Real" then DAE . T_REAL_DEFAULT ;
632- case "Integer" then DAE . T_INTEGER_DEFAULT ;
633- case "Boolean" then DAE . T_BOOL_DEFAULT ;
634- case "String" then DAE . T_STRING_DEFAULT ;
680+ case "Real" then DAE . T_REAL (type_attr, DAE . emptyTypeSource) ;
681+ case "Integer" then DAE . T_INTEGER (type_attr, DAE . emptyTypeSource) ;
682+ case "Boolean" then DAE . T_BOOL (type_attr, DAE . emptyTypeSource) ;
683+ case "String" then DAE . T_STRING (type_attr, DAE . emptyTypeSource) ;
635684 else DAE . T_UNKNOWN_DEFAULT ;
636685 end match;
637686
638687 else DAE . T_UNKNOWN_DEFAULT ;
639688 end match;
640689end makeType;
641690
691+ function makeTypeAttribute
692+ input Modifier modifier;
693+ output DAE . Var attribute;
694+ algorithm
695+ attribute := match modifier
696+ local
697+ DAE . Exp exp;
698+ DAE . Binding binding;
699+
700+ case Modifier . MODIFIER (binding = Binding . UNTYPED_BINDING (bindingExp = exp))
701+ algorithm
702+ binding := DAE . EQBOUND (exp, NONE (), DAE . C_UNKNOWN (),
703+ DAE . BindingSource . BINDING_FROM_START_VALUE ());
704+ then
705+ DAE . TYPES_VAR (modifier. name, DAE . dummyAttrVar, DAE . T_UNKNOWN_DEFAULT , binding, NONE ());
706+
707+ else
708+ algorithm
709+ print("NFInst.makeTypeAttribute: Bad modifier \n " );
710+ then
711+ fail();
712+
713+ end match;
714+ end makeTypeAttribute;
715+
642716function instBindings
643717 input output InstNode node;
644718 input output InstanceTree tree;
@@ -708,6 +782,11 @@ function instExp
708782 output InstanceTree tree = inTree;
709783algorithm
710784 daeExp := match absynExp
785+ local
786+ DAE . Exp exp1, exp2;
787+ DAE . Operator op;
788+ list< DAE . Exp > expl;
789+
711790 case Absyn . INTEGER () then DAE . ICONST (absynExp. value);
712791 case Absyn . REAL () then DAE . RCONST (stringReal(absynExp. value));
713792 case Absyn . STRING () then DAE . SCONST (absynExp. value);
@@ -718,10 +797,93 @@ algorithm
718797 then
719798 daeExp;
720799
800+ case Absyn . BINARY ()
801+ algorithm
802+ (exp1, tree) := instExp(absynExp. exp1, tree);
803+ (exp2, tree) := instExp(absynExp. exp2, tree);
804+ op := instOperator(absynExp. op);
805+ then
806+ DAE . BINARY (exp1, op, exp2);
807+
808+ case Absyn . UNARY ()
809+ algorithm
810+ (exp1, tree) := instExp(absynExp. exp, tree);
811+ op := instOperator(absynExp. op);
812+ then
813+ DAE . UNARY (op, exp1);
814+
815+ case Absyn . LBINARY ()
816+ algorithm
817+ (exp1, tree) := instExp(absynExp. exp1, tree);
818+ (exp2, tree) := instExp(absynExp. exp2, tree);
819+ op := instOperator(absynExp. op);
820+ then
821+ DAE . LBINARY (exp1, op, exp2);
822+
823+ case Absyn . LUNARY ()
824+ algorithm
825+ (exp1, tree) := instExp(absynExp. exp, tree);
826+ op := instOperator(absynExp. op);
827+ then
828+ DAE . LUNARY (op, exp1);
829+
830+ case Absyn . RELATION ()
831+ algorithm
832+ (exp1, tree) := instExp(absynExp. exp1, tree);
833+ (exp2, tree) := instExp(absynExp. exp2, tree);
834+ op := instOperator(absynExp. op);
835+ then
836+ DAE . RELATION (exp1, op, exp2, 0 , NONE ());
837+
838+ case Absyn . ARRAY ()
839+ algorithm
840+ (expl, tree) := List . mapFold(absynExp. arrayExp, instExp, tree);
841+ then
842+ DAE . ARRAY (DAE . T_UNKNOWN_DEFAULT , false , expl);
843+
844+ case Absyn . MATRIX ()
845+ algorithm
846+ (expl, tree) := List . mapFold(list(Absyn . ARRAY (e) for e in absynExp. matrix), instExp, tree);
847+ then
848+ DAE . ARRAY (DAE . T_UNKNOWN_DEFAULT , false , expl);
849+
721850 else DAE . SCONST ("ERROR" );
722851 end match;
723852end instExp;
724853
854+ protected function instOperator
855+ input Absyn . Operator inOperator;
856+ output DAE . Operator outOperator;
857+ algorithm
858+ outOperator := match(inOperator)
859+ case Absyn . ADD () then DAE . ADD (DAE . T_UNKNOWN_DEFAULT );
860+ case Absyn . SUB () then DAE . SUB (DAE . T_UNKNOWN_DEFAULT );
861+ case Absyn . MUL () then DAE . MUL (DAE . T_UNKNOWN_DEFAULT );
862+ case Absyn . DIV () then DAE . DIV (DAE . T_UNKNOWN_DEFAULT );
863+ case Absyn . POW () then DAE . POW (DAE . T_UNKNOWN_DEFAULT );
864+ case Absyn . UPLUS () then DAE . ADD (DAE . T_UNKNOWN_DEFAULT );
865+ case Absyn . UMINUS () then DAE . UMINUS (DAE . T_UNKNOWN_DEFAULT );
866+ case Absyn . ADD_EW () then DAE . ADD_ARR (DAE . T_UNKNOWN_DEFAULT );
867+ case Absyn . SUB_EW () then DAE . SUB_ARR (DAE . T_UNKNOWN_DEFAULT );
868+ case Absyn . MUL_EW () then DAE . MUL_ARR (DAE . T_UNKNOWN_DEFAULT );
869+ case Absyn . DIV_EW () then DAE . DIV_ARR (DAE . T_UNKNOWN_DEFAULT );
870+ case Absyn . POW_EW () then DAE . POW_ARR2 (DAE . T_UNKNOWN_DEFAULT );
871+ case Absyn . UPLUS_EW () then DAE . ADD (DAE . T_UNKNOWN_DEFAULT );
872+ case Absyn . UMINUS_EW () then DAE . UMINUS (DAE . T_UNKNOWN_DEFAULT );
873+ // logical have boolean type
874+ case Absyn . AND () then DAE . AND (DAE . T_BOOL_DEFAULT );
875+ case Absyn . OR () then DAE . OR (DAE . T_BOOL_DEFAULT );
876+ case Absyn . NOT () then DAE . NOT (DAE . T_BOOL_DEFAULT );
877+ // relational have boolean type too
878+ case Absyn . LESS () then DAE . LESS (DAE . T_BOOL_DEFAULT );
879+ case Absyn . LESSEQ () then DAE . LESSEQ (DAE . T_BOOL_DEFAULT );
880+ case Absyn . GREATER () then DAE . GREATER (DAE . T_BOOL_DEFAULT );
881+ case Absyn . GREATEREQ () then DAE . GREATEREQ (DAE . T_BOOL_DEFAULT );
882+ case Absyn . EQUAL () then DAE . EQUAL (DAE . T_BOOL_DEFAULT );
883+ case Absyn . NEQUAL () then DAE . NEQUAL (DAE . T_BOOL_DEFAULT );
884+ end match;
885+ end instOperator;
886+
725887function instCref
726888 input Absyn . ComponentRef absynCref;
727889 input InstanceTree inTree;
0 commit comments