Skip to content

Commit

Permalink
- Fixed handling of modifiers for nonexistent elements in new instant…
Browse files Browse the repository at this point in the history
…iation.

- Updated swedish translation of OMC.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@17847 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Oct 23, 2013
1 parent c1fe31c commit 8afe36d
Show file tree
Hide file tree
Showing 9 changed files with 401 additions and 454 deletions.
41 changes: 31 additions & 10 deletions Compiler/FrontEnd/NFEnv.mo
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ protected import Error;
protected import Flags;
protected import List;
protected import NFBuiltin;
protected import Util;

public type EntryOrigin = NFInstTypes.EntryOrigin;
public type Entry = NFInstTypes.Entry;
Expand Down Expand Up @@ -151,14 +152,15 @@ end isBuiltinScope;

public function makeInheritedOrigin
input SCode.Element inExtends;
input Integer inIndex;
input Env inEnv;
output EntryOrigin outOrigin;
protected
Absyn.Path bc;
Absyn.Info info;
algorithm
SCode.EXTENDS(baseClassPath = bc, info = info) := inExtends;
outOrigin := NFInstTypes.INHERITED_ORIGIN(bc, info, {}, inEnv);
outOrigin := NFInstTypes.INHERITED_ORIGIN(bc, info, {}, inEnv, inIndex);
end makeInheritedOrigin;

public function makeImportedOrigin
Expand Down Expand Up @@ -297,8 +299,23 @@ end mergeOrigin;
protected function mergeInheritedOrigin
"This function handles the case when an element has multiple origins from the
same base class, i.e. when an element is inherited from multiple sources in a
base class. In that case we can merge the sub-origins of those origins. Fails
if no matching origin is found."
base class. For example:
class A class B class C class D
Real x; Real x; extends A; extends C;
end A; end B; extends B; end D;
end C;

In this example we get two origins for x inherited from C:
INHERITED_ORIGIN(baseClass = C, origin = INHERITED_ORIGIN(baseClass = A))
INHERITED_ORIGIN(baseClass = C, origin = INHERITED_ORIGIN(baseClass = B))

This function searches for an existing origin with the same base class as the
new origin, and if found it merges them. In the example above we'd then get:
INHERITED_ORIGIN(baseClass = C, origin = {INHERITED_ORIGIN(baseClass = A),
INHERITED_ORIGIN(baseClass = B))

If no matching origin can be found the function fails."
input EntryOrigin inNewOrigin;
input list<EntryOrigin> inOldOrigins;
output list<EntryOrigin> outOrigins;
Expand All @@ -310,15 +327,16 @@ algorithm
Absyn.Info info;
EntryOrigin origin;
Env env;
Integer idx;

// Found two origins with the same base class, merge their origins.
case (NFInstTypes.INHERITED_ORIGIN(baseClass = bc1, origin = origin1),
NFInstTypes.INHERITED_ORIGIN(bc2, info, origin2, env) :: rest_origins)
NFInstTypes.INHERITED_ORIGIN(bc2, info, origin2, env, idx) :: rest_origins)
equation
true = Absyn.pathEqual(bc1, bc2);
origin2 = List.fold(origin1, mergeOrigin, origin2);
then
NFInstTypes.INHERITED_ORIGIN(bc2, info, origin2, env) :: rest_origins;
NFInstTypes.INHERITED_ORIGIN(bc2, info, origin2, env, idx) :: rest_origins;

// No match, search the rest.
case (_, origin :: rest_origins)
Expand Down Expand Up @@ -520,10 +538,11 @@ protected
Absyn.Info info;
list<EntryOrigin> origins;
Env env;
Integer idx;
algorithm
NFInstTypes.INHERITED_ORIGIN(bc, info, origins, env) := inOrigin1;
NFInstTypes.INHERITED_ORIGIN(bc, info, origins, env, idx) := inOrigin1;
origins := inOrigin2 :: origins;
outOrigin := NFInstTypes.INHERITED_ORIGIN(bc, info, origins, env);
outOrigin := NFInstTypes.INHERITED_ORIGIN(bc, info, origins, env, idx);
end collapseInheritedOrigins2;

public function insertElement
Expand Down Expand Up @@ -568,12 +587,14 @@ protected
AvlTree entries;
Env rest_env;
String entry_name;
Option<Entry> uentry;
algorithm
NFInstTypes.FRAME(name, ty, entries) :: rest_env := inEnv;
entry_name := entryName(inReplacement);
(entries, outWasReplaced) :=
(entries, uentry) :=
NFEnvAvlTree.update(entries, entry_name, replaceEntry2, (inReplacement, inOriginEnv));
outEnv := NFInstTypes.FRAME(name, ty, entries) :: rest_env;
outWasReplaced := Util.isSome(uentry);
end replaceEntry;

protected function replaceEntry2
Expand All @@ -596,7 +617,7 @@ public function updateEntry
input UpdateFunc inUpdateFunc;
input Env inEnv;
output Env outEnv;
output Boolean outWasUpdated;
output Option<Entry> outUpdatedEntry;

partial function UpdateFunc
input Entry inEntry;
Expand All @@ -612,7 +633,7 @@ protected
Env rest_env;
algorithm
NFInstTypes.FRAME(name, st, entries) :: rest_env := inEnv;
(entries, outWasUpdated) :=
(entries, outUpdatedEntry) :=
NFEnvAvlTree.update(entries, inName, inUpdateFunc, inArg);
outEnv := NFInstTypes.FRAME(name, st, entries) :: rest_env;
end updateEntry;
Expand Down
36 changes: 16 additions & 20 deletions Compiler/FrontEnd/NFEnvAvlTree.mo
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function update
input UpdateFunc inUpdateFunc;
input ArgType inArg;
output AvlTree outAvlTree;
output Boolean outWasUpdated;
output Option<AvlValue> outUpdatedValue;

partial function UpdateFunc
input AvlValue inValue;
Expand All @@ -322,22 +322,24 @@ public function update

replaceable type ArgType subtypeof Any;
algorithm
(outAvlTree, outWasUpdated) := match(inAvlTree, inKey, inUpdateFunc, inArg)
(outAvlTree, outUpdatedValue) :=
matchcontinue(inAvlTree, inKey, inUpdateFunc, inArg)
local
AvlKey key;
Integer key_comp;
AvlTree tree;
Boolean updated;
Option<AvlValue> updated_val;

case (NFInstTypes.AVLTREENODE(value = SOME(NFInstTypes.AVLTREEVALUE(key = key))), _, _, _)
equation
key_comp = stringCompare(key, inKey);
(tree, updated) =
(tree, updated_val) =
update2(inAvlTree, key_comp, inKey, inUpdateFunc, inArg);
then
(tree, updated);
(tree, updated_val);

end match;
else (inAvlTree, NONE());
end matchcontinue;
end update;

protected function update2
Expand All @@ -347,7 +349,7 @@ protected function update2
input UpdateFunc inUpdateFunc;
input ArgType inArg;
output AvlTree outAvlTree;
output Boolean outWasUpdated;
output Option<AvlValue> outUpdatedValue;

partial function UpdateFunc
input AvlValue inValue;
Expand All @@ -357,7 +359,7 @@ protected function update2

replaceable type ArgType subtypeof Any;
algorithm
(outAvlTree, outWasUpdated) :=
(outAvlTree, outUpdatedValue) :=
match(inAvlTree, inKeyComp, inKey, inUpdateFunc, inArg)
local
AvlKey key;
Expand All @@ -366,31 +368,25 @@ algorithm
Integer h;
AvlTree t;
Option<AvlTreeValue> oval;
Boolean updated;
Option<AvlValue> uval;

case (NFInstTypes.AVLTREENODE(SOME(NFInstTypes.AVLTREEVALUE(key, value)), h, left, right), 0, _, _, _)
equation
value = inUpdateFunc(value, inArg);
then
(NFInstTypes.AVLTREENODE(SOME(NFInstTypes.AVLTREEVALUE(key, value)), h, left, right), true);
(NFInstTypes.AVLTREENODE(SOME(NFInstTypes.AVLTREEVALUE(key, value)), h, left, right), SOME(value));

case (NFInstTypes.AVLTREENODE(oval, h, left, SOME(t)), -1, _, _, _)
equation
(t, updated) = update(t, inKey, inUpdateFunc, inArg);
(t, uval) = update(t, inKey, inUpdateFunc, inArg);
then
(NFInstTypes.AVLTREENODE(oval, h, left, SOME(t)), updated);
(NFInstTypes.AVLTREENODE(oval, h, left, SOME(t)), uval);

case (NFInstTypes.AVLTREENODE(oval, h, SOME(t), right), 1, _, _, _)
equation
(t, updated) = update(t, inKey, inUpdateFunc, inArg);
(t, uval) = update(t, inKey, inUpdateFunc, inArg);
then
(NFInstTypes.AVLTREENODE(oval, h, SOME(t), right), updated);

case (NFInstTypes.AVLTREENODE(_, _, _, NONE()), -1, _, _, _)
then (inAvlTree, false);

case (NFInstTypes.AVLTREENODE(_, _, NONE(), _), 1, _, _, _)
then (inAvlTree, false);
(NFInstTypes.AVLTREENODE(oval, h, SOME(t), right), uval);

end match;
end update2;
Expand Down
128 changes: 0 additions & 128 deletions Compiler/FrontEnd/NFInst.mo
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ algorithm
equation
// Enter the class scope.
env = NFLookup.enterEntryScope(inEntry, inClassMod, inEnv);
//mod = NFEnv.entryModifier(inEntry);
//mod = NFMod.mergeMod(inClassMod, mod);
//env = NFMod.addModToEnv(mod, env);

// Instantiate the class' elements.
(elems, es, globals) = instElementList(el, inPrefixes, env, inTypePath,
Expand Down Expand Up @@ -664,59 +661,6 @@ algorithm
end match;
end getBasicTypeAttrTypeString;




//protected function instBasicTypeAttribute
// input Modifier inMod;
// input NFSCodeEnv.AvlTree inAttributes;
// input Globals inGlobals;
// output DAE.Var outAttribute;
// output Globals outGlobals;
//algorithm
// (outAttribute, outGlobals) := match(inMod, inAttributes, inGlobals)
// local
// String ident, tspec;
// DAE.Type ty;
// Absyn.Exp bind_exp;
// DAE.Exp inst_exp;
// DAE.Binding binding;
// Env env;
// Prefix prefix;
// Globals globals;
// Absyn.Info info;
//
// case (NFInstTypes.MODIFIER(name = ident, subModifiers = {},
// binding = NFInstTypes.RAW_BINDING(bind_exp, env, prefix, _, _), info = info), _, globals)
// equation
// NFSCodeEnv.VAR(var = SCode.COMPONENT(typeSpec = Absyn.TPATH(path =
// Absyn.IDENT(tspec)))) = NFSCodeEnv.avlTreeGet(inAttributes, ident);
// ty = instBasicTypeAttributeType(tspec);
// (inst_exp, globals) = instExp(bind_exp, env, prefix, info, globals);
// binding = DAE.EQBOUND(inst_exp, NONE(), DAE.C_UNKNOWN(),
// DAE.BINDING_FROM_DEFAULT_VALUE());
// then
// (DAE.TYPES_VAR(ident, DAE.dummyAttrParam, ty, binding, NONE()), globals);
//
// // TODO: Print error message for invalid attributes.
// end match;
//end instBasicTypeAttribute;
//
//protected function instBasicTypeAttributeType
// input String inTypeName;
// output DAE.Type outType;
//algorithm
// outType := match(inTypeName)
// case "$RealType" then DAE.T_REAL_DEFAULT;
// case "$IntegerType" then DAE.T_INTEGER_DEFAULT;
// case "$BooleanType" then DAE.T_BOOL_DEFAULT;
// case "$StringType" then DAE.T_STRING_DEFAULT;
// case "$EnumType" then DAE.T_ENUMERATION_DEFAULT;
// case "StateSelect" then DAE.T_ENUMERATION_DEFAULT;
// end match;
//end instBasicTypeAttributeType;
//

protected function instElementList
input list<SCode.Element> inElements;
input Prefixes inPrefixes;
Expand Down Expand Up @@ -801,78 +745,6 @@ algorithm
end match;
end resolveElement;

//public function resolveRedeclaredElement
// "This function makes sure that an element is up-to-date in case it has been
// redeclared. This is achieved by looking the element up in the environment. In
// the case that the element has been redeclared, the environment where it should
// be instantiated is returned, otherwise the old environment."
// input tuple<SCode.Element, Modifier> inElement;
// input Env inEnv;
// input Prefix inPrefix;
// output tuple<SCode.Element, Modifier> outElement;
// output Modifier outOriginalMod;
// output Env outEnv;
// output list<tuple<NFSCodeEnv.Item, Env>> outPreviousItem;
//algorithm
// (outElement, outOriginalMod, outEnv, outPreviousItem) := match(inElement, inEnv, inPrefix)
// local
// Modifier mod, omod;
// String name;
// Item item;
// SCode.Element orig_el, new_el;
// Env env;
// Boolean b;
// list<tuple<NFSCodeEnv.Item, Env>> previousItem;
//
// // Only components which are actually replaceable needs to be looked up,
// // since non-replaceable components can't have been replaced.
// case ((orig_el as SCode.COMPONENT(name = name, prefixes =
// SCode.PREFIXES(replaceablePrefix = SCode.REPLACEABLE(_))), mod), _, _)
// equation
// (item, _) = NFSCodeLookup.lookupInClass(name, inEnv);
// (NFSCodeEnv.VAR(var = new_el), env, previousItem) = NFSCodeEnv.resolveRedeclaredItem(item, inEnv);
// omod = getOriginalMod(orig_el, inEnv, inPrefix);
// then
// ((new_el, mod), omod, env, previousItem);
//
// // Other elements doesn't need to be looked up. Extends may not be
// // replaceable, and classes are looked up in the environment anyway. The
// // exception is packages with constants, but those are handled in
// // instPackageConstants.
// else (inElement, NFInstTypes.NOMOD(), inEnv, {});
//
// end match;
//end resolveRedeclaredElement;
//
//protected function getOriginalMod
// input SCode.Element inOriginalElement;
// input Env inEnv;
// input Prefix inPrefix;
// output Modifier outModifier;
//algorithm
// outModifier := match(inOriginalElement, inEnv, inPrefix)
// local
// SCode.Ident name;
// Absyn.ArrayDim ad;
// Integer dim_count;
// SCode.Mod smod;
// Modifier mod;
//
// case (SCode.COMPONENT(modifications = SCode.NOMOD()), _, _)
// then NFInstTypes.NOMOD();
//
// case (SCode.COMPONENT(name = name, attributes = SCode.ATTR(arrayDims = ad),
// modifications = smod), _, _)
// equation
// dim_count = listLength(ad);
// mod = NFSCodeMod.translateMod(smod, name, dim_count, inPrefix, inEnv);
// then
// mod;
//
// end match;
//end getOriginalMod;
//

protected function instElement
input SCode.Element inElement;
input Modifier inModifier;
Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/NFInstTypes.mo
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ public uniontype EntryOrigin
Absyn.Info info "The info of the extends clause.";
list<EntryOrigin> origin "The origins of the element in the baseclass.";
Env originEnv "The environment the entry was inherited from.";
Integer index "Index used to identify the extends clause for optimization.";
end INHERITED_ORIGIN;

record REDECLARED_ORIGIN
Expand Down

0 comments on commit 8afe36d

Please sign in to comment.