Skip to content

Commit

Permalink
- addClassAnnotation has been moved to the typed API
Browse files Browse the repository at this point in the history
- Added OpenModelica.$Code.Expression
- Added support for named arguments that have Code type


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@12584 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Aug 18, 2012
1 parent da0b886 commit 08cf155
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 13 deletions.
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -930,6 +930,9 @@ public uniontype Type "models the different front-end and back-end types"
end Type;

public uniontype CodeType
record C_EXPRESSION
end C_EXPRESSION;

record C_TYPENAME
end C_TYPENAME;

Expand Down
1 change: 1 addition & 0 deletions Compiler/FrontEnd/Inst.mo
Expand Up @@ -1075,6 +1075,7 @@ algorithm
equation
{Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("$Code",Absyn.IDENT(name))))} = Types.getTypeSource(ty);
then Util.assoc(name,{
("Expression", DAE.T_CODE(DAE.C_EXPRESSION(),DAE.emptyTypeSource)),
("TypeName", DAE.T_CODE(DAE.C_TYPENAME(),DAE.emptyTypeSource)),
("VariableName", DAE.T_CODE(DAE.C_VARIABLENAME(),DAE.emptyTypeSource)),
("VariableNames", DAE.T_CODE(DAE.C_VARIABLENAMES(),DAE.emptyTypeSource))
Expand Down
14 changes: 14 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -703,6 +703,7 @@ encapsulated package OpenModelica "OpenModelica internal defintions and scriptin
type $Code "Code quoting is not a uniontype yet because that would require enabling MetaModelica extensions in the regular compiler.
Besides, it has special semantics."

type Expression "An expression of some kind" end Expression;
type TypeName "A path, for example the name of a class, e.g. A.B.C or .A.B" end TypeName;
type VariableName "A variable name, e.g. a.b or a[1].b[3].c" end VariableName;
type VariableNames "An array of variable names, e.g. {a.b,a[1].b[3].c}, or a single VariableName" end VariableNames;
Expand Down Expand Up @@ -843,6 +844,7 @@ end Internal;

package Scripting

import OpenModelica.$Code.Expression;
import OpenModelica.$Code.TypeName;
import OpenModelica.$Code.VariableName;
import OpenModelica.$Code.VariableNames;
Expand Down Expand Up @@ -2084,6 +2086,18 @@ external "builtin";
annotation(preferredView="text");
end closeSimulationResultFile;

function addClassAnnotation
input TypeName class_;
input Expression annotate;
output Boolean bool;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Used to set annotations, like Diagrams and Icons in classes. The function is given the name of the class
and the annotation to set.</p>
<p>Usage: addClassAnnotation(Modelica, annotate = Documentation(info = \"<html></html>\"))</p>
</html>"));
end addClassAnnotation;

function getAlgorithmCount "Counts the number of Algorithm sections in a class."
input TypeName class_;
output Integer count;
Expand Down
17 changes: 16 additions & 1 deletion Compiler/FrontEnd/Static.mo
Expand Up @@ -9588,6 +9588,7 @@ algorithm
list<Absyn.NamedArg> nas,narg;
list<DAE.FuncArg> farg;
Boolean impl;
DAE.CodeType ct;
Env.Cache cache;
DAE.Dimensions ds;
Prefix.Prefix pre;
Expand All @@ -9597,11 +9598,21 @@ algorithm
case (cache,_,{},_,slots,checkTypes,impl,polymorphicBindings,_,_,_)
then (cache,slots,{},polymorphicBindings);

case (cache, env, (Absyn.NAMEDARG(argName = id,argValue = e) :: nas), farg, slots, checkTypes as true, impl, polymorphicBindings,_,pre,info)
equation
(vt as DAE.T_CODE(ty=ct)) = findNamedArgType(id, farg);
e_1 = elabCodeExp(e,cache,env,ct,info);
slots_1 = fillSlot((id,vt,DAE.C_VAR(),NONE()), e_1, {}, slots,checkTypes,pre,info);
(cache,newslots,clist,polymorphicBindings) =
elabNamedInputArgs(cache, env, nas, farg, slots_1, checkTypes, impl, polymorphicBindings, st, pre, info);
then
(cache,newslots,(DAE.C_VAR() :: clist),polymorphicBindings);

// check types exact match
case (cache,env,(Absyn.NAMEDARG(argName = id,argValue = e) :: nas),farg,slots,checkTypes as true,impl,polymorphicBindings,st,pre,info)
equation
(cache,e_1,DAE.PROP(t,c1),_) = elabExp(cache, env, e, impl,st, true,pre,info);
vt = findNamedArgType(id, farg);
(cache,e_1,DAE.PROP(t,c1),_) = elabExp(cache, env, e, impl,st, true,pre,info);
(e_2,_,polymorphicBindings) = Types.matchTypePolymorphic(e_1,t,vt,Env.getEnvPathNoImplicitScope(env),polymorphicBindings,false);
slots_1 = fillSlot((id,vt,c1,NONE()), e_2, {}, slots,checkTypes,pre,info);
(cache,newslots,clist,polymorphicBindings) =
Expand Down Expand Up @@ -13937,6 +13948,10 @@ algorithm
DAE.Type et;
Integer i;
DAE.Exp dexp;

// Expression
case (_,_,_,DAE.C_EXPRESSION(),_)
then DAE.CODE(Absyn.C_EXPRESSION(exp),DAE.T_UNKNOWN_DEFAULT);

// Type Name
case (Absyn.CREF(componentRef=cr),_,_,DAE.C_TYPENAME(),_)
Expand Down
5 changes: 5 additions & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -1066,6 +1066,9 @@ algorithm
case Values.CODE(A=Absyn.C_TYPENAME(path=_))
then DAE.T_CODE(DAE.C_TYPENAME(), {});

case Values.CODE(A=Absyn.C_EXPRESSION(exp=_))
then DAE.T_CODE(DAE.C_EXPRESSION(), {});

case (v)
equation
str = "- Types.typeOfValue failed: " +& ValuesUtil.valString(v);
Expand Down Expand Up @@ -2281,6 +2284,7 @@ algorithm
str;

// Code
case (DAE.T_CODE(DAE.C_EXPRESSION(),_)) then "$Code(Expression)";
case (DAE.T_CODE(DAE.C_TYPENAME(),_)) then "$Code(TypeName)";
case (DAE.T_CODE(DAE.C_VARIABLENAME(),_)) then "$Code(VariableName)";
case (DAE.T_CODE(DAE.C_VARIABLENAMES(),_)) then "$Code(VariableName[:])";
Expand Down Expand Up @@ -6654,6 +6658,7 @@ public function printCodeTypeStr
output String str;
algorithm
str := match ct
case DAE.C_EXPRESSION() then "OpenModelica.Code.Expression";
case DAE.C_TYPENAME() then "OpenModelica.Code.TypeName";
case DAE.C_VARIABLENAME() then "OpenModelica.Code.VariableName";
case DAE.C_VARIABLENAMES() then "OpenModelica.Code.VariableNames";
Expand Down
13 changes: 12 additions & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -811,6 +811,7 @@ algorithm
DAE.Type tp;
Absyn.Class absynClass;
Absyn.ClassDef cdef;
Absyn.Exp aexp;
DAE.DAElist dae;
BackendDAE.BackendDAE daelow,optdae;
BackendDAE.Variables vars;
Expand Down Expand Up @@ -1776,7 +1777,17 @@ algorithm
((str1,str2)) = Interactive.getNamedAnnotation(classpath, p, "Documentation", SOME(("","")),Interactive.getDocumentationAnnotationString);
then
(cache,ValuesUtil.makeArray({Values.STRING(str1),Values.STRING(str2)}),st);


case (cache,env,"addClassAnnotation",{Values.CODE(Absyn.C_TYPENAME(classpath)),Values.CODE(Absyn.C_EXPRESSION(aexp))},Interactive.SYMBOLTABLE(p,aDep,_,ic,iv,cf,lf),msg)
equation
p = Interactive.addClassAnnotation(Absyn.pathToCref(classpath), Absyn.NAMEDARG("annotate",aexp)::{}, p);
then
(cache,Values.BOOL(true),Interactive.SYMBOLTABLE(p,aDep,NONE(),ic,iv,cf,lf));

case (cache,env,"addClassAnnotation",_,st as Interactive.SYMBOLTABLE(ast=p),msg)
then
(cache,Values.BOOL(false),st);

case (cache,env,"isPackage",{Values.CODE(Absyn.C_TYPENAME(classpath))},st as Interactive.SYMBOLTABLE(ast=p),msg)
equation
b = Interactive.isPackage(classpath, p);
Expand Down
14 changes: 3 additions & 11 deletions Compiler/Script/Interactive.mo
Expand Up @@ -1540,16 +1540,6 @@ algorithm
then
("true", st);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "addClassAnnotation");
{Absyn.CREF(componentRef = cr)} = getApiFunctionArgs(istmts);
nargs = getApiFunctionNamedArgs(istmts);
newp = addClassAnnotation(cr, nargs, p);
newst = setSymbolTableAST(st, newp);
then
("true",newst);

case (istmts, st as SYMBOLTABLE(ast = p))
equation
matchApiFunction(istmts, "getComponentCount");
Expand Down Expand Up @@ -10342,7 +10332,7 @@ algorithm
end matchcontinue;
end updateComponent;

protected function addClassAnnotation
public function addClassAnnotation
"function:addClassAnnotation
This function takes a `ComponentRef\' and an `Exp\' expression and a
`Program\' and adds the expression as a annotation to the specified
Expand All @@ -10360,6 +10350,7 @@ algorithm
Absyn.ComponentRef model_;
list<Absyn.NamedArg> nargs;
Absyn.TimeStamp ts;
Absyn.Exp exp;
case ((model_ as Absyn.CREF_QUAL(name = _)),nargs, p as Absyn.PROGRAM(globalBuildTimes=ts))
equation
modelpath = Absyn.crefToPath(model_) "Class inside other class" ;
Expand All @@ -10371,6 +10362,7 @@ algorithm
newp;
case ((model_ as Absyn.CREF_IDENT(name = _)),nargs,p as Absyn.PROGRAM(globalBuildTimes=ts))
equation
exp = Absyn.CALL(model_,Absyn.FUNCTIONARGS({},nargs));
modelpath = Absyn.crefToPath(model_) "Class on top level" ;
cdef = getPathedClassInProgram(modelpath, p);
cdef_1 = addClassAnnotationToClass(cdef, nargs);
Expand Down

0 comments on commit 08cf155

Please sign in to comment.