diff --git a/OMCompiler/Compiler/BackEnd/Unit.mo b/OMCompiler/Compiler/BackEnd/Unit.mo index 2bd2e4c10b8..229561b83a7 100644 --- a/OMCompiler/Compiler/BackEnd/Unit.mo +++ b/OMCompiler/Compiler/BackEnd/Unit.mo @@ -563,6 +563,7 @@ end prefix2String; public function parseUnitString "author: lochel The second argument is optional." input String inUnitString; + input SourceInfo info; input HashTableStringToUnit.HashTable inKnownUnits = getKnownUnits(); output Unit outUnit; protected @@ -573,7 +574,7 @@ algorithm if listEmpty(charList) then fail(); end if; - tokenList := lexer(charList); + tokenList := lexer(charList, info); outUnit := parser3({true, true}, tokenList, UNIT(1e0, 0, 0, 0, 0, 0, 0, 0), inKnownUnits); if not isUnit(outUnit) then fail(); @@ -809,6 +810,7 @@ end getPrefix; protected function lexer "author: lochel Tokenizer: charList to tokenList" input list inCharList; + input SourceInfo info; output list outTokenList; algorithm outTokenList := matchcontinue(inCharList) @@ -822,50 +824,50 @@ algorithm case {} then {}; case "."::charList equation - tokenList = lexer(charList); + tokenList = lexer(charList, info); then T_MUL()::tokenList; case "("::charList equation - tokenList = lexer(charList); + tokenList = lexer(charList, info); then T_LPAREN()::tokenList; case ")"::charList equation - tokenList = lexer(charList); + tokenList = lexer(charList, info); then T_RPAREN()::tokenList; case "/"::charList equation - tokenList = lexer(charList); + tokenList = lexer(charList, info); then T_DIV()::tokenList; case "+"::charList equation (charList, number) = popNumber(charList); false = (number == ""); - tokenList = lexer(charList); + tokenList = lexer(charList, info); i = stringInt(number); then T_NUMBER(i)::tokenList; case "-"::charList equation (charList, number) = popNumber(charList); false = (number == ""); - tokenList = lexer(charList); + tokenList = lexer(charList, info); i = -stringInt(number); then T_NUMBER(i)::tokenList; case charList equation (charList, number) = popNumber(charList); false = (number == ""); - tokenList = lexer(charList); + tokenList = lexer(charList, info); i = stringInt(number); then T_NUMBER(i)::tokenList; case charList equation (charList, unit) = popUnit(charList); false = (unit == ""); - tokenList = lexer(charList); + tokenList = lexer(charList, info); then T_UNIT(unit)::tokenList; else equation - Error.addInternalError("function lexer failed", sourceInfo()); + Error.addInternalError("function lexer failed: " + stringDelimitList(list("'" + c + "'" for c in inCharList), " "), info); then fail(); end matchcontinue; end lexer; diff --git a/OMCompiler/Compiler/BackEnd/UnitCheck.mo b/OMCompiler/Compiler/BackEnd/UnitCheck.mo index 2c2fe3ea8be..4a820881fd5 100644 --- a/OMCompiler/Compiler/BackEnd/UnitCheck.mo +++ b/OMCompiler/Compiler/BackEnd/UnitCheck.mo @@ -995,7 +995,7 @@ algorithm guard(unitString <> "") equation cr = BackendVariable.varCref(var); - (ut, HtS2U, HtU2S) = parse(unitString, cr, HtS2U, HtU2S); + (ut, HtS2U, HtU2S) = parse(unitString, cr, var.source.info, HtS2U, HtU2S); HtCr2U = BaseHashTable.add((cr,ut),HtCr2U); then ((HtCr2U, HtS2U, HtU2S)); @@ -1016,6 +1016,7 @@ end convertUnitString2unit; protected function parse "author: lochel" input String inUnitString; input DAE.ComponentRef inCref; + input SourceInfo info; input HashTableStringToUnit.HashTable inHtS2U; input HashTableUnitToString.HashTable inHtU2S; output Unit.Unit outUnit; @@ -1030,7 +1031,7 @@ algorithm then Unit.MASTER({inCref}); case _ - then Unit.parseUnitString(inUnitString, inHtS2U); + then Unit.parseUnitString(inUnitString, info, inHtS2U); else Unit.UNKNOWN(inUnitString); end matchcontinue; diff --git a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo index 70fbf98d86d..3767576276b 100644 --- a/OMCompiler/Compiler/SimCode/SimCodeUtil.mo +++ b/OMCompiler/Compiler/SimCode/SimCodeUtil.mo @@ -8184,7 +8184,7 @@ algorithm deriv.comment := "der(" + deriv.comment + ")"; end if; try - unit := Unit.parseUnitString(deriv.unit); + unit := Unit.parseUnitString(deriv.unit, state.source.info); unit := Unit.unitDiv(unit, Unit.UNIT(1e0, 0, 0, 0, 1, 0, 0, 0)); deriv.unit := Unit.unitString(unit); else @@ -9137,7 +9137,7 @@ algorithm if not stringEq(var.unit, "") and not BaseHashSet.has(var.unit, unitNameKeys) then unitNameKeys := BaseHashSet.add(var.unit, unitNameKeys); try - unit := Unit.parseUnitString(var.unit); // get the SI- units information + unit := Unit.parseUnitString(var.unit, var.source.info); // get the SI- units information unitDefinitions := SimCode.UNITDEFINITION(var.unit, transformUnitToBaseUnit(unit)) :: unitDefinitions; else // catch the units which are not calculated