Skip to content

Commit 2c634e1

Browse files
committed
- removed templateError() imported function (from my previous commit) ... to be replaced by the new approach:
- introduced new magic builtin function sourceInfo() that returns contextual Absyn.Info structure based on the position in template files. The sourceInfo() can only be used as a direct parameter into a template/imported function,... no let binding of its value is possible for now (to be possible when full semantics of the let will be implemented) - added two Tpl functions Tpl.addSourceTemplateError() and Tpl.addTemplateError() to SimCodeTV.mo which can be used to implement user defined templates for reporting template errors, - see error() and errorMsg() example templates in SimCodeC.tpl and one usage of error() in literalExpConstBoxedVal() template - Susan compiler now fully captures source info for every expression, so the proper semantic errors are on the way "to be really soon ..." git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8264 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 76eb523 commit 2c634e1

File tree

9 files changed

+518
-330
lines changed

9 files changed

+518
-330
lines changed

Compiler/BackEnd/SimCode.mo

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -818,35 +818,6 @@ algorithm
818818
end appendLists;
819819

820820

821-
//TODO: ?? should this function be in Tpl.mo ?
822-
public function templateError
823-
"Reports a template error via the Error module."
824-
input String inErrMsg;
825-
output String outErrMsg;
826-
827-
algorithm
828-
outErrMsg := matchcontinue (inErrMsg)
829-
local
830-
String errmsg;
831-
case (inErrMsg)
832-
equation
833-
errmsg = "TemplateError '" +& inErrMsg +& "'";
834-
//TODO: create a special category for this error ... Error.TEMPLATE_ERROR
835-
Error.addMessage(Error.INTERNAL_ERROR, {errmsg});
836-
errmsg = "###>>> " +& errmsg +& " <<<###"; //to be output in the generated code
837-
then
838-
errmsg;
839-
840-
case (_)
841-
equation
842-
Debug.fprint("failtrace", "-!!!Tpl.textFile failed - a system error ?\n");
843-
then
844-
fail();
845-
846-
end matchcontinue;
847-
end templateError;
848-
849-
850821
/** end of TypeView published functions **/
851822

852823

Compiler/Template/Tpl.mo

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ protected import Util;
88
protected import Print;
99
protected import CevalScript;
1010
protected import Error;
11+
public import Absyn;
1112

1213

1314
// indentation will be implemented through spaces
@@ -91,21 +92,6 @@ uniontype IterOptions
9192
end ITER_OPTIONS;
9293
end IterOptions;
9394

94-
95-
uniontype SourceInfo "
96-
The _sourceinfo_ type ... source location information.
97-
It is copied from Absyn.Info (for now) to prevent direct dependency from Absyn to Tpl and TplAbsyn,
98-
perhaps, it will be changed to Absyn.Info in the future (easy to do then)."
99-
record SOURCE_INFO
100-
String fileName;
101-
//Boolean isReadOnly "isReadOnly : (true|false). Should be true for libraries" ;
102-
Integer lineNumberStart;
103-
Integer columnNumberStart;
104-
Integer lineNumberEnd;
105-
Integer columnNumberEnd ;
106-
//TimeStamp buildTimes "Build and edit times";
107-
end SOURCE_INFO;
108-
end SourceInfo;
10995

11096
//by default, we will parse new lines in every non-token string
11197
public function writeStr
@@ -1681,6 +1667,36 @@ algorithm
16811667
// fail();
16821668
end matchcontinue;
16831669
end textFile;
1670+
1671+
1672+
public function sourceInfo
1673+
"Magic sourceInfo() function implementation"
1674+
input String inFileName;
1675+
input Integer inLineNum;
1676+
input Integer inColumnNum;
1677+
1678+
output Absyn.Info outSourceInfo;
1679+
algorithm
1680+
outSourceInfo := Absyn.INFO(inFileName, false, inLineNum, inColumnNum, inLineNum, inColumnNum, Absyn.dummyTimeStamp);
1681+
end sourceInfo;
16841682

16851683

1684+
//we do not import Error.addSourceMessage() directly
1685+
//because of list creation in Susan is not possible (yet by design)
1686+
public function addSourceTemplateError
1687+
"Wraps call to Error.addSourceMessage() funtion with Error.TEMPLATE_ERROR and one MessageToken."
1688+
input String inErrMsg;
1689+
input Absyn.Info inInfo;
1690+
algorithm
1691+
Error.addSourceMessage(Error.TEMPLATE_ERROR, {inErrMsg}, inInfo);
1692+
end addSourceTemplateError;
1693+
1694+
//for completeness
1695+
public function addTemplateError
1696+
"Wraps call to Error.addMessage() funtion with Error.TEMPLATE_ERROR and one MessageToken."
1697+
input String inErrMsg;
1698+
algorithm
1699+
Error.addMessage(Error.TEMPLATE_ERROR, {inErrMsg});
1700+
end addTemplateError;
1701+
16861702
end Tpl;

0 commit comments

Comments
 (0)