Skip to content

Commit b62a72f

Browse files
committed
- Better error-messages for operator record requiring operator function members and the other way around
- Fix LoadCompilerSources not setting echo(true) if echo was disabled git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@18645 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent b4c8101 commit b62a72f

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

Compiler/FrontEnd/NFSCodeDependency.mo

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ protected import List;
5454
protected import NFSCodeCheck;
5555
protected import NFSCodeFlattenRedeclare;
5656
protected import NFSCodeLookup;
57+
protected import SCodeDump;
5758
protected import System;
5859
protected import Util;
5960

@@ -851,7 +852,7 @@ algorithm
851852
SCode.Ident name;
852853
SCode.Prefixes prefixes;
853854
SCode.Restriction res;
854-
String errorMessage;
855+
String str;
855856
list<Extends> exts;
856857
list<NFSCodeEnv.Redeclaration> redecls;
857858
NFSCodeFlattenRedeclare.Replacements repls;
@@ -909,11 +910,9 @@ algorithm
909910
//operators in any other class type are error.
910911
case (SCode.CLASS(name = name, restriction=SCode.R_OPERATOR(), info = info), _, _, _)
911912
equation
912-
//mahge: FIX HERE.
913-
errorMessage = "operators are allowed in OPERATOR RECORD only. Error on:" +& name;
914-
Error.addSourceMessage(Error.LOOKUP_ERROR, {errorMessage, name}, info);
915-
then
916-
fail();
913+
str = SCodeDump.restrString(inClassRestriction);
914+
Error.addSourceMessage(Error.OPERATOR_FUNCTION_NOT_EXPECTED, {name, str}, info);
915+
then fail();
917916

918917
//operator functions in operator record might be used later.
919918
case (SCode.CLASS(name = name, restriction=SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()), info = info), _, _, SCode.R_RECORD(true))
@@ -925,9 +924,8 @@ algorithm
925924
//operators functions in any other class type are error.
926925
case (SCode.CLASS(name = name, restriction=SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()), info = info), _, _, _)
927926
equation
928-
//mahge: FIX HERE.
929-
errorMessage = "Operator functions are allowed in OPERATOR RECORD only. Error on:" +& name;
930-
Error.addSourceMessage(Error.LOOKUP_ERROR, {errorMessage, name}, info);
927+
str = SCodeDump.restrString(inClassRestriction);
928+
Error.addSourceMessage(Error.OPERATOR_FUNCTION_NOT_EXPECTED, {name, str}, info);
931929
then
932930
fail();
933931

@@ -944,9 +942,8 @@ algorithm
944942
case (SCode.CLASS(name = name, restriction = res, info = info), _, _, SCode.R_OPERATOR())
945943
equation
946944
false = SCode.isFunctionOrExtFunctionRestriction(res);
947-
//mahge: FIX HERE.
948-
errorMessage = "Operators can only contain functions. Error on:" +& name;
949-
Error.addSourceMessage(Error.LOOKUP_ERROR, {errorMessage, name}, info);
945+
str = SCodeDump.restrString(res);
946+
Error.addSourceMessage(Error.OPERATOR_FUNCTION_EXPECTED, {name, str}, info);
950947
then
951948
fail();
952949

Compiler/FrontEnd/SCodeDump.mo

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,34 @@ public function restrString
9090
output String outString;
9191
algorithm
9292
outString := match (inRestriction)
93-
case SCode.R_CLASS() then "CLASS";
94-
case SCode.R_OPTIMIZATION() then "OPTIMIZATION";
95-
case SCode.R_MODEL() then "MODEL";
96-
case SCode.R_RECORD(false) then "RECORD";
97-
case SCode.R_RECORD(true) then "OPERATOR_RECORD";
98-
case SCode.R_BLOCK() then "BLOCK";
99-
case SCode.R_CONNECTOR(false) then "CONNECTOR";
100-
case SCode.R_CONNECTOR(true) then "EXPANDABLE_CONNECTOR";
101-
case SCode.R_OPERATOR() then "OPERATOR";
102-
case SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION(false)) then "PURE FUNCTION";
103-
case SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION(true)) then "IMPURE FUNCTION";
104-
case SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()) then "OPERATOR_FUNCTION";
105-
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION(false)) then "PURE EXTERNAL_FUNCTION";
106-
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION(true)) then "IMPURE PURE EXTERNAL_FUNCTION";
107-
case SCode.R_FUNCTION(SCode.FR_RECORD_CONSTRUCTOR()) then "RECORD_CONSTRUCTOR";
108-
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then "PARALLEL FUNCTION";
109-
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then "KERNEL_FUNCTION";
110-
case SCode.R_TYPE() then "TYPE";
111-
case SCode.R_PACKAGE() then "PACKAGE";
112-
case SCode.R_ENUMERATION() then "ENUMERATION";
113-
case SCode.R_METARECORD(index=_) then "METARECORD";
114-
case SCode.R_UNIONTYPE() then "UNIONTYPE";
93+
case SCode.R_CLASS() then "class";
94+
case SCode.R_OPTIMIZATION() then "optimization";
95+
case SCode.R_MODEL() then "model";
96+
case SCode.R_RECORD(false) then "record";
97+
case SCode.R_RECORD(true) then "operator record";
98+
case SCode.R_BLOCK() then "block";
99+
case SCode.R_CONNECTOR(false) then "connector";
100+
case SCode.R_CONNECTOR(true) then "expandable connector";
101+
case SCode.R_OPERATOR() then "operator";
102+
case SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION(false)) then "pure function";
103+
case SCode.R_FUNCTION(SCode.FR_NORMAL_FUNCTION(true)) then "impure function";
104+
case SCode.R_FUNCTION(SCode.FR_OPERATOR_FUNCTION()) then "operator function";
105+
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION(false)) then "pure external function";
106+
case SCode.R_FUNCTION(SCode.FR_EXTERNAL_FUNCTION(true)) then "impure external function";
107+
case SCode.R_FUNCTION(SCode.FR_RECORD_CONSTRUCTOR()) then "record constructor";
108+
case SCode.R_FUNCTION(SCode.FR_PARALLEL_FUNCTION()) then "parallel function";
109+
case SCode.R_FUNCTION(SCode.FR_KERNEL_FUNCTION()) then "kernel function";
110+
case SCode.R_TYPE() then "type";
111+
case SCode.R_PACKAGE() then "package";
112+
case SCode.R_ENUMERATION() then "enumeration";
113+
case SCode.R_METARECORD(index=_) then "metarecord";
114+
case SCode.R_UNIONTYPE() then "uniontype";
115115
// predefined types
116-
case SCode.R_PREDEFINED_INTEGER() then "PREDEFINED_INT";
117-
case SCode.R_PREDEFINED_REAL() then "PREDEFINED_REAL";
118-
case SCode.R_PREDEFINED_STRING() then "PREDEFINED_STRING";
119-
case SCode.R_PREDEFINED_BOOLEAN() then "PREDEFINED_BOOL";
120-
case SCode.R_PREDEFINED_ENUMERATION() then "PREDEFINED_ENUM";
116+
case SCode.R_PREDEFINED_INTEGER() then "Integer";
117+
case SCode.R_PREDEFINED_REAL() then "Real";
118+
case SCode.R_PREDEFINED_STRING() then "String";
119+
case SCode.R_PREDEFINED_BOOLEAN() then "Boolean";
120+
case SCode.R_PREDEFINED_ENUMERATION() then "enumeration";
121121
end match;
122122
end restrString;
123123

Compiler/Util/Error.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,10 @@ public constant Message SLICE_ASSIGN_NON_ARRAY = MESSAGE(226, SCRIPTING(), ERROR
613613
Util.gettext("Cannot assign slice to non-initialized array %s."));
614614
public constant Message EXTERNAL_ARG_WRONG_EXP = MESSAGE(227, TRANSLATION(), ERROR(),
615615
Util.gettext("Expression %s cannot be an external argument. Only simple identifiers, constant scalars, and size-expressions are allowed."));
616+
public constant Message OPERATOR_FUNCTION_NOT_EXPECTED = MESSAGE(228, TRANSLATION(), ERROR(),
617+
Util.gettext("Only classes of type 'operator record' may contain elements of type 'operator function'; %s was found in a class that has restriction '%s'."));
618+
public constant Message OPERATOR_FUNCTION_EXPECTED = MESSAGE(229, TRANSLATION(), ERROR(),
619+
Util.gettext("'operator record' classes may only contain elements of type 'operator function'; %s has restriction '%s'."));
616620

617621
public constant Message UNBOUND_PARAMETER_WITH_START_VALUE_WARNING = MESSAGE(499, TRANSLATION(), WARNING(),
618622
Util.gettext("Parameter %s has no value, and is fixed during initialization (fixed=true), using available start value (start=%s) as default value."));

0 commit comments

Comments
 (0)