101101import de .darmstadt .tu .crossing .crySL .UseBlock ;
102102import de .darmstadt .tu .crossing .crySL .impl .DomainmodelImpl ;
103103import de .darmstadt .tu .crossing .crySL .impl .ObjectImpl ;
104+ import com .google .common .base .CharMatcher ;
104105
105106public class CrySLParser {
106107
@@ -340,7 +341,13 @@ private List<CrySLPredicate> retrieveReqPredFromAltPreds(ReqPred left) {
340341 private CrySLPredicate extractReqPred (final ReqPred pred ) {
341342 final List <ICrySLPredicateParameter > variables = new ArrayList <>();
342343 PredLit innerPred = (PredLit ) pred ;
343- final Constraint conditional = (Constraint ) innerPred .getCons ();
344+ EObject cons = innerPred .getCons ();
345+ ISLConstraint conditional = null ;
346+ if (cons instanceof Constraint ) {
347+ conditional = getConstraint ((Constraint ) cons );
348+ } else if (cons instanceof Pred ) {
349+ conditional = getPredicate ((Pred ) cons );
350+ }
344351 if (innerPred .getPred ().getParList () != null ) {
345352 for (final SuPar var : innerPred .getPred ().getParList ().getParameters ()) {
346353 if (var .getVal () != null ) {
@@ -361,7 +368,45 @@ private CrySLPredicate extractReqPred(final ReqPred pred) {
361368 }
362369 }
363370 }
364- return new CrySLPredicate (null , innerPred .getPred ().getPredName (), variables , (innerPred .getNot () != null ? true : false ), getConstraint (conditional ));
371+ return new CrySLPredicate (null , innerPred .getPred ().getPredName (), variables , (innerPred .getNot () != null ? true : false ), conditional );
372+ }
373+
374+ private ISLConstraint getPredicate (Pred pred ) {
375+ final List <ICrySLPredicateParameter > variables = new ArrayList <>();
376+ if (pred .getParList () != null ) {
377+ for (final SuPar var : pred .getParList ().getParameters ()) {
378+ if (var .getVal () != null ) {
379+ final LiteralExpression lit = var .getVal ();
380+ final ObjectImpl object = (ObjectImpl ) ((LiteralExpression ) lit .getLit ().getName ()).getValue ();
381+ final String type = ((ObjectDecl ) object .eContainer ()).getObjectType ().getQualifiedName ();
382+ final String variable = object .getName ();
383+ final String part = var .getVal ().getPart ();
384+ if (part != null ) {
385+ variables .add (new CrySLObject (variable , type , new CrySLSplitter (Integer .parseInt (lit .getInd ()), filterQuotes (lit .getSplit ()))));
386+ } else {
387+ final String consPred = var .getVal ().getConsPred ();
388+ int ind ;
389+ if (consPred != null ) {
390+ if (consPred .equals ("alg(" )) {
391+ ind = 0 ;
392+ variables .add (new CrySLObject (variable , type , new CrySLSplitter (ind , filterQuotes ("/" ))));
393+ } else if (consPred .equals ("mode(" )) {
394+ ind = 1 ;
395+ variables .add (new CrySLObject (variable , type , new CrySLSplitter (ind , filterQuotes ("/" ))));
396+ } else if (consPred .equals ("pad(" )) {
397+ ind = 2 ;
398+ variables .add (new CrySLObject (variable , type , new CrySLSplitter (ind , filterQuotes ("/" ))));
399+ }
400+ } else {
401+ variables .add (new CrySLObject (variable , type ));
402+ }
403+ }
404+ } else {
405+ variables .add (new CrySLObject (UNDERSCORE , NULL ));
406+ }
407+ }
408+ }
409+ return new CrySLPredicate (null , pred .getPredName (), variables , (((PredLit )pred .eContainer ()).getNot () != null ? true : false ), null );
365410 }
366411
367412 private CrySLArithmeticConstraint convertLiteralToArithmetic (final Constraint expression ) {
@@ -752,4 +797,8 @@ private String getValueOfLiteral(final EObject name) {
752797 }
753798 return Utils .filterQuotes (value );
754799 }
800+
801+ private static String filterQuotes (final String dirty ) {
802+ return CharMatcher .anyOf ("\" " ).removeFrom (dirty );
803+ }
755804}
0 commit comments