@@ -5807,5 +5807,386 @@ algorithm
58075807 end match;
58085808end isEmptyClassDef;
58095809
5810+ function stripCommentsFromProgram
5811+ "Strips all annotations and/or comments from a program."
5812+ input output Program program;
5813+ input Boolean stripAnnotations;
5814+ input Boolean stripComments;
5815+ algorithm
5816+ program := list(stripCommentsFromElement(e, stripAnnotations, stripComments) for e in program);
5817+ end stripCommentsFromProgram;
5818+
5819+ function stripCommentsFromElement
5820+ input output Element element;
5821+ input Boolean stripAnn;
5822+ input Boolean stripCmt;
5823+ algorithm
5824+ () := match element
5825+ case Element . EXTENDS ()
5826+ algorithm
5827+ if stripAnn then
5828+ element. ann := NONE ();
5829+ end if ;
5830+
5831+ element. modifications := stripCommentsFromMod(element. modifications, stripAnn, stripCmt);
5832+ then
5833+ ();
5834+
5835+ case Element . CLASS ()
5836+ algorithm
5837+ element. classDef := stripCommentsFromClassDef(element. classDef, stripAnn, stripCmt);
5838+ element. cmt := stripCommentsFromComment(element. cmt, stripAnn, stripCmt);
5839+ then
5840+ ();
5841+
5842+ case Element . COMPONENT ()
5843+ algorithm
5844+ element. modifications := stripCommentsFromMod(element. modifications, stripAnn, stripCmt);
5845+ element. comment := stripCommentsFromComment(element. comment, stripAnn, stripCmt);
5846+ then
5847+ ();
5848+
5849+ else ();
5850+ end match;
5851+ end stripCommentsFromElement;
5852+
5853+ function stripCommentsFromMod
5854+ input output Mod mod;
5855+ input Boolean stripAnn;
5856+ input Boolean stripCmt;
5857+ algorithm
5858+ () := match mod
5859+ case Mod . MOD ()
5860+ algorithm
5861+ mod. subModLst := list(stripCommentsFromSubMod(m, stripAnn, stripCmt) for m in mod. subModLst);
5862+ then
5863+ ();
5864+
5865+ case Mod . REDECL ()
5866+ algorithm
5867+ mod. element := stripCommentsFromElement(mod. element, stripAnn, stripCmt);
5868+ then
5869+ ();
5870+
5871+ else ();
5872+ end match;
5873+ end stripCommentsFromMod;
5874+
5875+ function stripCommentsFromSubMod
5876+ input output SubMod submod;
5877+ input Boolean stripAnn;
5878+ input Boolean stripCmt;
5879+ algorithm
5880+ submod. mod := stripCommentsFromMod(submod. mod, stripAnn, stripCmt);
5881+ end stripCommentsFromSubMod;
5882+
5883+ function stripCommentsFromClassDef
5884+ input output ClassDef cdef;
5885+ input Boolean stripAnn;
5886+ input Boolean stripCmt;
5887+ algorithm
5888+ cdef := match cdef
5889+ local
5890+ list< Element > el;
5891+ list< Equation > eql, ieql;
5892+ list< AlgorithmSection > alg, ialg;
5893+ Option < ExternalDecl > ext;
5894+
5895+ case ClassDef . PARTS ()
5896+ algorithm
5897+ el := list(stripCommentsFromElement(e, stripAnn, stripCmt) for e in cdef. elementLst);
5898+ eql := list(stripCommentsFromEquation(eq, stripAnn, stripCmt) for eq in cdef. normalEquationLst);
5899+ ieql := list(stripCommentsFromEquation(ieq, stripAnn, stripCmt) for ieq in cdef. initialEquationLst);
5900+ alg := list(stripCommentsFromAlgorithm(a, stripAnn, stripCmt) for a in cdef. normalAlgorithmLst);
5901+ ialg := list(stripCommentsFromAlgorithm(ia, stripAnn, stripCmt) for ia in cdef. initialAlgorithmLst);
5902+ ext := stripCommentsFromExternalDecl(cdef. externalDecl, stripAnn, stripCmt);
5903+ then
5904+ ClassDef . PARTS (el, eql, ieql, alg, ialg, cdef. constraintLst, cdef. clsattrs, ext);
5905+
5906+ case ClassDef . CLASS_EXTENDS ()
5907+ algorithm
5908+ cdef. modifications := stripCommentsFromMod(cdef. modifications, stripAnn, stripCmt);
5909+ cdef. composition := stripCommentsFromClassDef(cdef. composition, stripAnn, stripCmt);
5910+ then
5911+ cdef;
5912+
5913+ case ClassDef . DERIVED ()
5914+ algorithm
5915+ cdef. modifications := stripCommentsFromMod(cdef. modifications, stripAnn, stripCmt);
5916+ then
5917+ cdef;
5918+
5919+ case ClassDef . ENUMERATION ()
5920+ algorithm
5921+ cdef. enumLst := list(stripCommentsFromEnum(e, stripAnn, stripCmt) for e in cdef. enumLst);
5922+ then
5923+ cdef;
5924+
5925+ else cdef;
5926+ end match;
5927+ end stripCommentsFromClassDef;
5928+
5929+ function stripCommentsFromEnum
5930+ input output Enum enum;
5931+ input Boolean stripAnn;
5932+ input Boolean stripCmt;
5933+ algorithm
5934+ enum. comment := stripCommentsFromComment(enum. comment, stripAnn, stripCmt);
5935+ end stripCommentsFromEnum;
5936+
5937+ function stripCommentsFromComment
5938+ input output Comment cmt;
5939+ input Boolean stripAnn;
5940+ input Boolean stripCmt;
5941+ algorithm
5942+ if stripAnn then
5943+ cmt. annotation_ := NONE ();
5944+ end if ;
5945+
5946+ if stripCmt then
5947+ cmt. comment := NONE ();
5948+ end if ;
5949+ end stripCommentsFromComment;
5950+
5951+ function stripCommentsFromExternalDecl
5952+ input output Option < ExternalDecl > extDecl;
5953+ input Boolean stripAnn;
5954+ input Boolean stripCmt;
5955+ protected
5956+ ExternalDecl ext_decl;
5957+ algorithm
5958+ if isSome(extDecl) and stripAnn then
5959+ SOME (ext_decl) := extDecl;
5960+ ext_decl. annotation_ := NONE ();
5961+ extDecl := SOME (ext_decl);
5962+ end if ;
5963+ end stripCommentsFromExternalDecl;
5964+
5965+ function stripCommentsFromEquation
5966+ input output Equation eq;
5967+ input Boolean stripAnn;
5968+ input Boolean stripCmt;
5969+ algorithm
5970+ eq. eEquation := stripCommentsFromEEquation(eq. eEquation, stripAnn, stripCmt);
5971+ end stripCommentsFromEquation;
5972+
5973+ function stripCommentsFromEEquation
5974+ input output EEquation eq;
5975+ input Boolean stripAnn;
5976+ input Boolean stripCmt;
5977+ algorithm
5978+ () := match eq
5979+ case EEquation . EQ_IF ()
5980+ algorithm
5981+ eq. thenBranch := list(
5982+ list(stripCommentsFromEEquation(e, stripAnn, stripCmt) for e in branch)
5983+ for branch in eq. thenBranch);
5984+ eq. elseBranch := list(stripCommentsFromEEquation(e, stripAnn, stripCmt) for e in eq. elseBranch);
5985+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
5986+ then
5987+ ();
5988+
5989+ case EEquation . EQ_EQUALS ()
5990+ algorithm
5991+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
5992+ then
5993+ ();
5994+
5995+ case EEquation . EQ_PDE ()
5996+ algorithm
5997+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
5998+ then
5999+ ();
6000+
6001+ case EEquation . EQ_CONNECT ()
6002+ algorithm
6003+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6004+ then
6005+ ();
6006+
6007+ case EEquation . EQ_FOR ()
6008+ algorithm
6009+ eq. eEquationLst := list(stripCommentsFromEEquation(e, stripAnn, stripCmt) for e in eq. eEquationLst);
6010+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6011+ then
6012+ ();
6013+
6014+ case EEquation . EQ_WHEN ()
6015+ algorithm
6016+ eq. eEquationLst := list(stripCommentsFromEEquation(e, stripAnn, stripCmt) for e in eq. eEquationLst);
6017+ eq. elseBranches := list(stripCommentsFromWhenEqBranch(b, stripAnn, stripCmt) for b in eq. elseBranches);
6018+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6019+ then
6020+ ();
6021+
6022+ case EEquation . EQ_ASSERT ()
6023+ algorithm
6024+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6025+ then
6026+ ();
6027+
6028+ case EEquation . EQ_TERMINATE ()
6029+ algorithm
6030+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6031+ then
6032+ ();
6033+
6034+ case EEquation . EQ_REINIT ()
6035+ algorithm
6036+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6037+ then
6038+ ();
6039+
6040+ case EEquation . EQ_NORETCALL ()
6041+ algorithm
6042+ eq. comment := stripCommentsFromComment(eq. comment, stripAnn, stripCmt);
6043+ then
6044+ ();
6045+
6046+ end match;
6047+ end stripCommentsFromEEquation;
6048+
6049+ function stripCommentsFromWhenEqBranch
6050+ input output tuple< Absyn . Exp , list< EEquation >> branch;
6051+ input Boolean stripAnn;
6052+ input Boolean stripCmt;
6053+ protected
6054+ Absyn . Exp cond;
6055+ list< EEquation > body;
6056+ algorithm
6057+ (cond, body) := branch;
6058+ body := list(stripCommentsFromEEquation(e, stripAnn, stripCmt) for e in body);
6059+ branch := (cond, body);
6060+ end stripCommentsFromWhenEqBranch;
6061+
6062+ function stripCommentsFromAlgorithm
6063+ input output AlgorithmSection alg;
6064+ input Boolean stripAnn;
6065+ input Boolean stripCmt;
6066+ algorithm
6067+ alg. statements := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in alg. statements);
6068+ end stripCommentsFromAlgorithm;
6069+
6070+ function stripCommentsFromStatement
6071+ input output Statement stmt;
6072+ input Boolean stripAnn;
6073+ input Boolean stripCmt;
6074+ algorithm
6075+ () := match stmt
6076+ case Statement . ALG_ASSIGN ()
6077+ algorithm
6078+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6079+ then
6080+ ();
6081+
6082+ case Statement . ALG_IF ()
6083+ algorithm
6084+ stmt. trueBranch := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. trueBranch);
6085+ stmt. elseIfBranch := list(stripCommentsFromStatementBranch(b, stripAnn, stripCmt) for b in stmt. elseIfBranch);
6086+ stmt. elseBranch := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. elseBranch);
6087+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6088+ then
6089+ ();
6090+
6091+ case Statement . ALG_FOR ()
6092+ algorithm
6093+ stmt. forBody := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. forBody);
6094+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6095+ then
6096+ ();
6097+
6098+ case Statement . ALG_PARFOR ()
6099+ algorithm
6100+ stmt. parforBody := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. parforBody);
6101+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6102+ then
6103+ ();
6104+
6105+ case Statement . ALG_WHILE ()
6106+ algorithm
6107+ stmt. whileBody := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. whileBody);
6108+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6109+ then
6110+ ();
6111+
6112+ case Statement . ALG_WHEN_A ()
6113+ algorithm
6114+ stmt. branches := list(stripCommentsFromStatementBranch(b, stripAnn, stripCmt) for b in stmt. branches);
6115+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6116+ then
6117+ ();
6118+
6119+ case Statement . ALG_ASSERT ()
6120+ algorithm
6121+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6122+ then
6123+ ();
6124+
6125+ case Statement . ALG_TERMINATE ()
6126+ algorithm
6127+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6128+ then
6129+ ();
6130+
6131+ case Statement . ALG_REINIT ()
6132+ algorithm
6133+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6134+ then
6135+ ();
6136+
6137+ case Statement . ALG_NORETCALL ()
6138+ algorithm
6139+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6140+ then
6141+ ();
6142+
6143+ case Statement . ALG_RETURN ()
6144+ algorithm
6145+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6146+ then
6147+ ();
6148+
6149+ case Statement . ALG_BREAK ()
6150+ algorithm
6151+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6152+ then
6153+ ();
6154+
6155+ case Statement . ALG_FAILURE ()
6156+ algorithm
6157+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6158+ then
6159+ ();
6160+
6161+ case Statement . ALG_TRY ()
6162+ algorithm
6163+ stmt. body := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. body);
6164+ stmt. elseBody := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in stmt. elseBody);
6165+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6166+ then
6167+ ();
6168+
6169+ case Statement . ALG_CONTINUE ()
6170+ algorithm
6171+ stmt. comment := stripCommentsFromComment(stmt. comment, stripAnn, stripCmt);
6172+ then
6173+ ();
6174+
6175+ end match;
6176+ end stripCommentsFromStatement;
6177+
6178+ function stripCommentsFromStatementBranch
6179+ input output tuple< Absyn . Exp , list< Statement >> branch;
6180+ input Boolean stripAnn;
6181+ input Boolean stripCmt;
6182+ protected
6183+ Absyn . Exp cond;
6184+ list< Statement > body;
6185+ algorithm
6186+ (cond, body) := branch;
6187+ body := list(stripCommentsFromStatement(s, stripAnn, stripCmt) for s in body);
6188+ branch := (cond, body);
6189+ end stripCommentsFromStatementBranch;
6190+
58106191annotation(__OpenModelica_Interface= "frontend" );
58116192end SCode ;
0 commit comments