Skip to content

Commit

Permalink
- Added checks for valid class types of components in SCodeInst.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11493 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
perost committed Mar 22, 2012
1 parent c1a7519 commit 6fdb6d6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
51 changes: 48 additions & 3 deletions Compiler/FrontEnd/SCodeCheck.mo
Expand Up @@ -41,11 +41,12 @@ encapsulated package SCodeCheck
public import Absyn;
public import SCode;
public import SCodeEnv;
public import SCodeInst;
public import InstTypes;

protected import Config;
protected import Dump;
protected import Error;
protected import InstUtil;
protected import List;
protected import Util;
protected import SCodeDump;
Expand Down Expand Up @@ -591,8 +592,8 @@ algorithm
end checkIdentNotEqTypeName;

public function checkComponentsEqual
input SCodeInst.Component inComponent1;
input SCodeInst.Component inComponent2;
input InstTypes.Component inComponent1;
input InstTypes.Component inComponent2;
algorithm
_ := match(inComponent1, inComponent2)
case (_, _)
Expand All @@ -604,4 +605,48 @@ algorithm
end match;
end checkComponentsEqual;

public function checkInstanceRestriction
input SCodeEnv.Item inItem;
input InstTypes.Prefix inPrefix;
input Absyn.Info inInfo;
algorithm
_ := matchcontinue(inItem, inPrefix, inInfo)
local
SCode.Restriction res;
String pre_str, res_str;

case (SCodeEnv.CLASS(cls = SCode.CLASS(restriction = res)), _, _)
equation
true = isInstantiableClassRestriction(res);
then
();

case (SCodeEnv.CLASS(cls = SCode.CLASS(restriction = res)), _, _)
equation
res_str = SCodeDump.restrictionStringPP(res);
pre_str = InstUtil.printPrefix(inPrefix);
Error.addSourceMessage(Error.INVALID_CLASS_RESTRICTION,
{res_str, pre_str}, inInfo);
then
fail();

end matchcontinue;
end checkInstanceRestriction;

protected function isInstantiableClassRestriction
input SCode.Restriction inRestriction;
output Boolean outIsInstantiable;
algorithm
outIsInstantiable := match(inRestriction)
case SCode.R_CLASS() then true;
case SCode.R_MODEL() then true;
case SCode.R_RECORD() then true;
case SCode.R_BLOCK() then true;
case SCode.R_CONNECTOR(isExpandable = _) then true;
case SCode.R_TYPE() then true;
case SCode.R_ENUMERATION() then true;
else false;
end match;
end isInstantiableClassRestriction;

end SCodeCheck;
6 changes: 5 additions & 1 deletion Compiler/FrontEnd/SCodeInst.mo
Expand Up @@ -56,6 +56,7 @@ protected import Flags;
protected import InstSymbolTable;
protected import InstUtil;
protected import List;
protected import SCodeCheck;
protected import SCodeExpand;
protected import SCodeFlattenRedeclare;
protected import SCodeLookup;
Expand Down Expand Up @@ -578,12 +579,15 @@ algorithm
condition = NONE(), info = info), _, _, _, _)
equation
// Look up the class of the component.
(item, path, env) = SCodeLookup.lookupClassName(path, inEnv, info);
(item, _, env) = SCodeLookup.lookupClassName(path, inEnv, info);

// Instantiate array dimensions and add them to the prefix.
dims = instDimensions(ad, inEnv, inPrefix);
prefix = InstUtil.addPrefix(name, dims, inPrefix);

// Check that it's legal to instantiate the class.
SCodeCheck.checkInstanceRestriction(item, prefix, info);

// Merge the class modifications with this elements' modifications.
dim_count = listLength(ad);
mod = SCodeMod.translateMod(smod, name, dim_count, inPrefix, inEnv);
Expand Down
2 changes: 2 additions & 0 deletions Compiler/Util/Error.mo
Expand Up @@ -583,6 +583,8 @@ public constant Message SIMPLIFY_CONSTANT_ERROR = MESSAGE(218, TRANSLATION(), NO
"The compiler failed to perform constant folding on expression %s. Please report this bug to the developers and we will fix it as soon as possible (using the +t compiler option if possible).");
public constant Message SUM_EXPECTED_ARRAY = MESSAGE(219, TRANSLATION(), ERROR(),
"In sum(%s), the expression is of type %s, but is required to be of builtin array type (of any number of dimensions).");
public constant Message INVALID_CLASS_RESTRICTION = MESSAGE(220, TRANSLATION(), ERROR(),
"Invalid specialized class type '%s' for component %s.");

public constant Message UNBOUND_PARAMETER_WARNING = MESSAGE(500, TRANSLATION(), WARNING(),
"Parameter %s has neither value nor start value, and is fixed during initialization (fixed=true)");
Expand Down

0 comments on commit 6fdb6d6

Please sign in to comment.