diff --git a/Compiler/BackEnd/SimCodeUtil.mo b/Compiler/BackEnd/SimCodeUtil.mo index 6f75acc4a9e..74297635c87 100644 --- a/Compiler/BackEnd/SimCodeUtil.mo +++ b/Compiler/BackEnd/SimCodeUtil.mo @@ -3175,7 +3175,7 @@ algorithm // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); (tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(path))) = Expression.typeof(e1); // tmp - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); crtmp = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); tempvars = createTempVars(varLst, crtmp, itempvars); // 0 = a - tmp @@ -3197,7 +3197,7 @@ algorithm // ((e2_1, (_, _))) = BackendDAEUtil.extendArrExp((e2, (NONE(), false))); (tp as DAE.T_COMPLEX(varLst=varLst, complexClassType=ClassInf.RECORD(path))) = Expression.typeof(e2); // tmp - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); crtmp = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); tempvars = createTempVars(varLst, crtmp, itempvars); // 0 = a - tmp @@ -3218,7 +3218,7 @@ algorithm ((e2_1, (_, _))) = BackendDAEUtil.extendArrExp((e2, (NONE(), false))); // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); // tmp = f() - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); cr = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); e1_1 = Expression.crefExp(cr); stms = DAE.STMT_ASSIGN(tp, e1_1, e2_1, source); @@ -3239,7 +3239,7 @@ algorithm ((e1_1, (_, _))) = BackendDAEUtil.extendArrExp((e2, (NONE(), false))); // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); // tmp = f() - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); cr = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); e2_1 = Expression.crefExp(cr); stms = DAE.STMT_ASSIGN(tp, e2_1, e1_1, source); @@ -3259,7 +3259,7 @@ algorithm // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); // tmp = f() tp = Expression.typeof(e1); - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); cr = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); crexplst = List.map1(expl, Expression.generateCrefsExpFromExp, cr); stms = DAE.STMT_TUPLE_ASSIGN(tp, crexplst, e2, source); @@ -5234,7 +5234,7 @@ algorithm case (DAE.T_COMPLEX(complexClassType = ClassInf.RECORD(name), varLst = varlst, source = {_}), accRecDecls, rt) equation - sname = Absyn.pathStringReplaceDot(name, "_"); + sname = Absyn.pathStringUnquoteReplaceDot(name, "_"); false = listMember(sname, rt); vars = List.map(varlst, typesVarNoBinding); vars = List.sort(vars,compareVariable); @@ -5249,7 +5249,7 @@ algorithm case (DAE.T_METARECORD( fields = varlst, source = {path}), accRecDecls, rt) equation - sname = Absyn.pathStringReplaceDot(path, "_"); + sname = Absyn.pathStringUnquoteReplaceDot(path, "_"); false = listMember(sname, rt); fieldNames = List.map(varlst, generateVarName); accRecDecls = SimCode.RECORD_DECL_DEF(path, fieldNames) :: accRecDecls; @@ -5327,7 +5327,7 @@ algorithm case ({}, accRecDecls, rt) then (accRecDecls, rt); case (DAE.METARECORDCALL(path=path, fieldNames=fieldNames)::rest, accRecDecls, rt) equation - name = Absyn.pathStringReplaceDot(path, "_"); + name = Absyn.pathStringUnquoteReplaceDot(path, "_"); b = listMember(name, rt); accRecDecls = List.consOnTrue(not b, SimCode.RECORD_DECL_DEF(path, fieldNames), accRecDecls); rt_1 = List.consOnTrue(not b, name, rt); @@ -5946,7 +5946,7 @@ algorithm ((e2_1, (_, _))) = BackendDAEUtil.extendArrExp((e2, (NONE(), false))); // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); // tmp = f() - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); cr1 = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); e1_1 = Expression.crefExp(cr1); stms = DAE.STMT_ASSIGN(tp, e1_1, e2_1, source); @@ -5971,7 +5971,7 @@ algorithm ((e1_1, (_, _))) = BackendDAEUtil.extendArrExp((e1, (NONE(), false))); // true = ComponentReference.crefEqualNoStringCompare(cr, cr2); // tmp = f() - ident = Absyn.pathStringReplaceDot(path, "_"); + ident = Absyn.pathStringUnquoteReplaceDot(path, "_"); cr1 = ComponentReference.makeCrefIdent("$TMP_" +& ident +& intString(iuniqueEqIndex), tp, {}); e2_1 = Expression.crefExp(cr1); stms = DAE.STMT_ASSIGN(tp, e2_1, e1_1, source); @@ -12107,7 +12107,7 @@ algorithm String aliasStr; case (_,_,_) equation - aliasStr = Absyn.pathStringReplaceDot(BaseHashTable.get(str, inHt),"_"); + aliasStr = Absyn.pathStringUnquoteReplaceDot(BaseHashTable.get(str, inHt),"_"); then (SOME(aliasStr),inHt); else equation diff --git a/Compiler/BackEnd/XMLDump.mo b/Compiler/BackEnd/XMLDump.mo index 91ba2fa79a5..6834cf2aedf 100644 --- a/Compiler/BackEnd/XMLDump.mo +++ b/Compiler/BackEnd/XMLDump.mo @@ -2356,7 +2356,7 @@ algorithm case (s :: remaining) equation s_path = Absyn.pathStringNoQual(s); - fn_name_str = Absyn.pathStringReplaceDot(s, "_"); + fn_name_str = Absyn.pathStringUnquoteReplaceDot(s, "_"); fn_name_str = stringAppend("_", fn_name_str); Print.printBuf("\n<");Print.printBuf(FUNCTION); Print.printBuf(" ");Print.printBuf(FUNCTION_ORIGNAME);Print.printBuf("=\"");Print.printBuf(s_path);Print.printBuf("\""); diff --git a/Compiler/FrontEnd/Absyn.mo b/Compiler/FrontEnd/Absyn.mo index 9a5e8f08aa3..d4819bbf5ff 100644 --- a/Compiler/FrontEnd/Absyn.mo +++ b/Compiler/FrontEnd/Absyn.mo @@ -2571,34 +2571,25 @@ algorithm outString := stringDelimitList(pathToStringList(path),delimiter); end pathString2NoLeadingDot; -public function pathStringReplaceDot "Helper function to pathString." +public function pathStringUnquoteReplaceDot +" Changes a path to string. Uses the input string as separator. + If the separtor exists in the string then it is doubled (sep _ then + a_b changes to a__b) before delimiting + (Replaces dots with that separator). And also unquotes each ident. +" input Path inPath; - input String inString; + input String repStr; output String outString; -algorithm - outString:= - match (inPath,inString) - local - String s,ns,s1,ss,str,dstr,safe_s; - Path n; - case (IDENT(name = s),str) - equation - dstr = stringAppend(str, str); - safe_s = System.stringReplace(s, str, dstr); - then - safe_s; - case(FULLYQUALIFIED(n),str) then pathStringReplaceDot(n,str); - case (QUALIFIED(name = s,path = n),str) - equation - ns = pathStringReplaceDot(n, str); - dstr = stringAppend(str, str); - safe_s = System.stringReplace(s, str, dstr); - s1 = stringAppend(safe_s, str); - ss = stringAppend(s1, ns); - then - ss; - end match; -end pathStringReplaceDot; +protected + list strlst; + String rep_rep; +algorithm + rep_rep := repStr +& repStr; + strlst := pathToStringList(inPath); + strlst := List.map2(strlst,System.stringReplace, repStr, rep_rep); + strlst := List.map(strlst,System.unquoteIdentifier); + outString := stringDelimitList(strlst,repStr); +end pathStringUnquoteReplaceDot; public function stringPath "Converts a string into a qualified path." diff --git a/Compiler/Script/CevalScript.mo b/Compiler/Script/CevalScript.mo index 3ee404169cc..b2af054c601 100644 --- a/Compiler/Script/CevalScript.mo +++ b/Compiler/Script/CevalScript.mo @@ -5038,7 +5038,7 @@ protected function generateFunctionName input Absyn.Path functionPath; output String functionName; algorithm - functionName := System.unquoteIdentifier(Absyn.pathStringReplaceDot(functionPath, "_")); + functionName := Absyn.pathStringUnquoteReplaceDot(functionPath, "_"); end generateFunctionName; protected function generateFunctionFileName @@ -5051,8 +5051,7 @@ algorithm local String name, n1, n2; Integer len; case (_) equation - name = Absyn.pathStringReplaceDot(functionPath, "_"); - name = System.unquoteIdentifier(name); + name = Absyn.pathStringUnquoteReplaceDot(functionPath, "_"); len = stringLength(name); // not bigger than true = len > Global.maxFunctionFileLength; @@ -5064,8 +5063,7 @@ algorithm name; case (_) equation - name = Absyn.pathStringReplaceDot(functionPath, "_"); - name = System.unquoteIdentifier(name); + name = Absyn.pathStringUnquoteReplaceDot(functionPath, "_"); then name; end matchcontinue; diff --git a/Compiler/Script/Interactive.mo b/Compiler/Script/Interactive.mo index 604d545a241..fd7f02d50fb 100644 --- a/Compiler/Script/Interactive.mo +++ b/Compiler/Script/Interactive.mo @@ -9356,7 +9356,7 @@ algorithm case (GlobalScript.CFunction(functionInCf,_,funcHandle,_,_) :: rest, _) equation true = Absyn.pathEqual(functionInCf, functionName); - _ = Absyn.pathStringReplaceDot(functionName, "_"); + // _ = Absyn.pathStringUnquoteReplaceDot(functionName, "_"); System.freeFunction(funcHandle, Flags.isSet(Flags.DYN_LOAD)); res = removeCf(rest, functionName); then