Skip to content

Commit

Permalink
- Inst.addCachedEnv moved to Env.addCachedEnv (is more natural to be …
Browse files Browse the repository at this point in the history
…in Env)

- Static.transformModificationsToNamedArguments (does what the long name say)
- Lookup.lookupType2 reordered cases
- Codegen - generate modelica_integer and integer for enumeration type.
  testsuite/mosfiles/Enum8.mos will fail because of this. To be fixed later.
- more comments in Inst
- Exp.crefEqual was checking for equality:
  + by comparing idents/subscripts by using
    equality(n1, n2) instead of true = stringEqual(n1, n2)
  + as a last resort (last case) by *converting*
    the crefs into strings and doing string comparison
    on them??!!
  + I changed all equality(n1, n2) into true = stringEqual(n1, n2)
    and improved the last case to handle stringified crefs better:
    CREF_QUAL(x, CREF_IDENT(y)) will be equal to CREF_IDENT(x.y).

- Inst.isInnerOuterMatch now compares the last
  indents from crefs before doing the Exp.crefEqual.
- Inst.propagateAttributes is now walking the DAE once
- Changed the walking the DAE two times:
   innerVars =
     DAEUtil.getAllMatchingElements(inDae,DAEUtil.isInnerVar);
   outerVars =
     DAEUtil.getAllMatchingElements(inDae,DAEUtil.isOuterVar);
  To walking the DAE once:
   (innerVars,outerVars) =
     DAEUtil.findAllMatchingElements(
               inDae,DAEUtil.isInnerVar,DAEUtil.isOuterVar);
- Inst.instClassIn and Inst.partialInstClassIn are now cached (only one input/result for now)
  + this needs to be developed more as the cache should be cleared after instantiation of
    the top class is done.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4686 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 14, 2009
1 parent 61a4330 commit 8b65b69
Show file tree
Hide file tree
Showing 7 changed files with 1,523 additions and 541 deletions.
5 changes: 3 additions & 2 deletions Compiler/Codegen.mo
Expand Up @@ -1822,7 +1822,7 @@ algorithm
case DAE.ET_STRING() then "string";
case DAE.ET_BOOL() then "boolean";
case DAE.ET_OTHER() then "complex"; // Only use is currently for external objects. Perhaps in future also records.
case DAE.ET_ENUMERATION(_,_,_,_) then "enumeration";
case DAE.ET_ENUMERATION(_,_,_,_) then "integer";
// case Exp.ENUM() then "ENUM_NOT_IMPLEMENTED";
case DAE.ET_FUNCTION_REFERENCE_VAR() then "fnptr";
case DAE.ET_FUNCTION_REFERENCE_FUNC() then "fnptr";
Expand Down Expand Up @@ -2032,10 +2032,11 @@ algorithm
String t_str,name;
DAE.Type t_1,t,ty;

case ((DAE.T_INTEGER(varLstInt = _),_)) then "modelica_integer";
case ((DAE.T_INTEGER(varLstInt = _),_)) then "modelica_integer";
case ((DAE.T_REAL(varLstReal = _),_)) then "modelica_real";
case ((DAE.T_STRING(varLstString = _),_)) then "modelica_string";
case ((DAE.T_BOOL(varLstBool = _),_)) then "modelica_boolean";
case ((DAE.T_ENUMERATION(varLst=_),_)) then "modelica_integer";
case ((DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(name)),_))
equation
t_str = stringAppend("struct ", name);
Expand Down
131 changes: 84 additions & 47 deletions Compiler/Env.mo
@@ -1,7 +1,7 @@
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-2008, Linköpings University,
* Copyright (c) 1998-2009, Linköpings University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
Expand Down Expand Up @@ -112,19 +112,19 @@ public uniontype CacheTree
end CacheTree;

type CSetsType = tuple<list<DAE.ComponentRef>,DAE.ComponentRef>;

public
uniontype Frame
record FRAME
Option<Ident> optName "Optional class name" ;
AvlTree clsAndVars "List of uniquely named classes and variables" ;
AvlTree types "List of types, which DOES NOT be uniquely named, eg. size have several types" ;
list<Item> imports "list of unnamed items (imports)" ;
list<Frame> inherited "list of frames for inherited elements" ;
CSetsType connectionSet "current connection set crefs" ;
Boolean isEncapsulated "encapsulated bool=true means that FRAME is created due to encapsulated class" ;
Option<Ident> optName "Optional class name";
AvlTree clsAndVars "List of uniquely named classes and variables";
AvlTree types "List of types, which DOES NOT be uniquely named, eg. size have several types";
list<Item> imports "list of unnamed items (imports)";
list<Frame> inherited "list of frames for inherited elements";
CSetsType connectionSet "current connection set crefs";
Boolean isEncapsulated "encapsulated bool=true means that FRAME is created due to encapsulated class";
list<SCode.Element> defineUnits "list of units defined in the frame";
end FRAME;

end Frame;

public uniontype InstStatus
Expand All @@ -147,11 +147,9 @@ public
uniontype Item
record VAR
DAE.Var instantiated "instantiated component" ;
Option<tuple<SCode.Element, DAE.Mod>> declaration "declaration if not fully instantiated." ;
InstStatus instStatus "if it untyped, typed or fully instantiated (dae)" ;
Env env "The environment of the instantiated component
Contains e.g. all sub components
" ;
Option<tuple<SCode.Element, DAE.Mod>> declaration "declaration if not fully instantiated.";
InstStatus instStatus "if it untyped, typed or fully instantiated (dae)";
Env env "The environment of the instantiated component. Contains e.g. all sub components";
end VAR;

record CLASS
Expand All @@ -170,7 +168,8 @@ uniontype Item
end Item;

public
type Env = list<Frame>;
type Env = list<Frame>
"an environment is a list of frames";

protected import Dump;
protected import Exp;
Expand All @@ -179,27 +178,26 @@ protected import Util;
protected import System;
protected import Types;
protected import Inst;
protected import Debug;

public constant Env emptyEnv={} "- Values" ;

//public constant Cache emptyCache = CACHE(NONE,NONE);

public function emptyCache
"returns an empty cache"
output Cache cache;

protected Option<EnvCache>[:] arr;
protected
Option<EnvCache>[:] arr;
algorithm
//print("EMPTYCACHE\n");
arr := listArray({NONE});
cache := CACHE(arr,NONE);
end emptyCache;

public function newFrame "- Relations
function: newFrame
// functions for dealing with the environment

public function newFrame "function: newFrame
This function creates a new frame, which includes setting up the
hashtable for the frame.
"
hashtable for the frame."
input Boolean enc;
output Frame outFrame;
AvlTree httypes;
Expand Down Expand Up @@ -1185,6 +1183,36 @@ algorithm
end matchcontinue;
end cacheAdd;

// moved from Inst as is more natural to be here!
public function addCachedEnv
"function: addCachedEnv
add a new environment in the cache obtaining a new cache"
input Cache inCache;
input String id;
input Env env;
output Cache outCache;
algorithm
outCache := matchcontinue(inCache,id,env)
local
Absyn.Path path,newPath;

case(inCache,id,env)
equation
SOME(path) = getEnvPath(env);
outCache = cacheAdd(path,inCache,env);
then outCache;

case(inCache,id,env)
equation
// this should be placed in the global environment
// how do we do that??
Debug.fprintln("env", "<<<< Env.addCachedEnv - failed to add env to cache for: " +&
printEnvPathStr(env) +& " [" +& id +& "]");
then inCache;

end matchcontinue;
end addCachedEnv;

protected function cacheGetEnv "get an environment from the tree cache."
input Absyn.Path scope;
input Absyn.Path path;
Expand Down Expand Up @@ -1290,29 +1318,38 @@ algorithm
Env globalEnv,oldEnv;
list<CacheTree> children,children2;
CacheTree child;
// simple names already added
case (Absyn.IDENT(id),(tree as CACHETREE(globalID,globalEnv,CACHETREE(id2,oldEnv,children)::children2)),env)
equation
//print(id);print(" already added\n");
equality(id=id2);
then tree;

// simple names already added
case (Absyn.IDENT(id),(tree as CACHETREE(globalID,globalEnv,CACHETREE(id2,oldEnv,children)::children2)),env)
equation
//print(id);print(" already added\n");
equality(id=id2);
// shouldn't we replace it?
// Debug.fprintln("env", ">>>> Env.cacheAdd - already in cache: " +& printEnvPathStr(env));
then tree;

// simple names try next
case (Absyn.IDENT(id),tree as CACHETREE(globalID,globalEnv,child::children),env)
equation
CACHETREE(globalID,globalEnv,children) = cacheAddEnv(Absyn.IDENT(id),CACHETREE(globalID,globalEnv,children),env);
then CACHETREE(globalID,globalEnv,child::children);

// Simple names, not found
case (Absyn.IDENT(id),CACHETREE(globalID,globalEnv,{}),env)
then CACHETREE(globalID,globalEnv,{CACHETREE(id,env,{})});
// simple names try next
case (Absyn.IDENT(id),tree as CACHETREE(globalID,globalEnv,child::children),env)
equation
CACHETREE(globalID,globalEnv,children) = cacheAddEnv(Absyn.IDENT(id),CACHETREE(globalID,globalEnv,children),env);
then CACHETREE(globalID,globalEnv,child::children);

// Simple names, not found
case (Absyn.IDENT(id),CACHETREE(globalID,globalEnv,{}),env)
equation
// Debug.fprintln("env", ">>>> Env.cacheAdd - add to cache: " +& printEnvPathStr(env));
then CACHETREE(globalID,globalEnv,{CACHETREE(id,env,{})});

// Qualified names.
// Qualified names.
case (path as Absyn.QUALIFIED(_,_),CACHETREE(globalID,globalEnv,children),env)
equation
children=cacheAddEnv2(path,children,env);
then CACHETREE(globalID,globalEnv,children);
case (path,_,_) equation print("cacheAddEnv path=");print(Absyn.pathString(path));print(" failed\n");

// failure
case (path,_,_)
equation
print("cacheAddEnv path=");print(Absyn.pathString(path));print(" failed\n");
then fail();
end matchcontinue;
end cacheAddEnv;
Expand All @@ -1331,7 +1368,7 @@ algorithm
CacheTree child;
Env env2;

// qualified name, found matching
// qualified name, found matching
case(Absyn.QUALIFIED(id,path),CACHETREE(id2,env2,children2)::children,env)
equation
equality(id=id2);
Expand All @@ -1342,10 +1379,11 @@ algorithm
case (Absyn.IDENT(id),CACHETREE(id2,env2,children2)::children,env)
equation
equality(id=id2);
// Debug.fprintln("env", ">>>> Env.cacheAdd - already in cache: " +& printEnvPathStr(env));
//print("single name, found matching\n");
then CACHETREE(id2,env2,children2)::children;

// try next
// try next
case(path,child::children,env)
equation
//print("try next\n");
Expand All @@ -1356,13 +1394,15 @@ algorithm
case (Absyn.QUALIFIED(id,path),{},env)
equation
children = cacheAddEnv2(path,{},env);
// Debug.fprintln("env", ">>>> Env.cacheAdd - add to cache: " +& printEnvPathStr(env));
//print("qualified name no child found, create one.\n");
then {CACHETREE(id,emptyEnv,children)};

// simple name no child found, create one.
case (Absyn.IDENT(id),{},env)
equation
//print("simple name no child found, create one.\n");
// print("simple name no child found, create one.\n");
// Debug.fprintln("env", ">>>> Env.cacheAdd - add to cache: " +& printEnvPathStr(env));
then {CACHETREE(id,env,{})};

case (_,_,_) equation print("cacheAddEnv2 failed\n"); then fail();
Expand Down Expand Up @@ -2284,8 +2324,5 @@ algorithm
end matchcontinue;
end getHeight;




end Env;

2 changes: 1 addition & 1 deletion Compiler/ExpandableConnectors.mo
Expand Up @@ -77,7 +77,7 @@ algorithm
InstanceHierarchy.InstanceHierarchy ih;
SCode.Program programWithPatchedExpandableConnectors;

case (inProgram, false)
case (inProgram, /* false */_)
then (InstanceHierarchy.emptyInstanceHierarchy, inProgram);

case (inProgram, true)
Expand Down

0 comments on commit 8b65b69

Please sign in to comment.