コード例 #1
0
 private static final Set<String> varDependenciesOf(final Statement s) {
   Set<String> list = new HashSet();
   for (Facet facet : EGaml.getFacetsOf(s)) {
     Expression expr = facet.getExpr();
     if (expr != null) {
       if (expr instanceof VariableRef) {
         list.add(EGaml.getKey.caseVariableRef((VariableRef) expr));
       } else {
         for (TreeIterator<EObject> tree = expr.eAllContents(); tree.hasNext(); ) {
           EObject obj = tree.next();
           if (obj instanceof VariableRef) {
             list.add(EGaml.getKey.caseVariableRef((VariableRef) obj));
           }
         }
       }
     }
   }
   if (list.isEmpty()) {
     return null;
   }
   return list;
 }
コード例 #2
0
 private static String convertAssignment(
     final S_Assignment stm,
     String keyword,
     final ISyntacticElement elt,
     final Expression expr,
     final Set<Diagnostic> errors) {
   IExpressionDescription value = convExpr(stm.getValue(), errors);
   if (keyword.endsWith("<-") || keyword.equals(SET)) {
     // Translation of "container[index] <- value" to
     // "put item: value in: container at: index"
     // 20/1/14: Translation of container[index] +<- value" to
     // "add item: value in: container at: index"
     if (expr instanceof Access && expr.getOp().equals("[")) {
       String kw = keyword.equals("+<-") ? ADD : PUT;
       String to = keyword.equals("+<-") ? TO : IN;
       elt.setKeyword(kw);
       addFacet(elt, ITEM, value, errors);
       addFacet(elt, to, convExpr(expr.getLeft(), errors), errors);
       List<Expression> args = EGaml.getExprsOf(((Access) expr).getArgs());
       if (args.size() == 0) {
         // Add facet all: true when no index is provided
         addFacet(elt, ALL, ConstantExpressionDescription.create(true), errors);
       } else {
         if (args.size() == 1) { // Integer index
           addFacet(elt, AT, convExpr(args.get(0), errors), errors);
         } else { // Point index
           IExpressionDescription p =
               new OperatorExpressionDescription(
                   POINT, convExpr(args.get(0), errors), convExpr(args.get(1), errors));
           addFacet(elt, AT, p, errors);
         }
       }
       keyword = kw;
     } else {
       // Translation of "var <- value" to "set var value: value"
       elt.setKeyword(SET);
       addFacet(elt, VALUE, value, errors);
       keyword = SET;
     }
   } else if (keyword.startsWith("<<") || keyword.equals("<+")) {
     // Translation of "container <+ item" or "container << item" to "add item: item to: container"
     // 08/01/14: Addition of the "<<+" (add all)
     elt.setKeyword(ADD);
     addFacet(elt, TO, convExpr(expr, errors), errors);
     addFacet(elt, ITEM, value, errors);
     if (keyword.equals("<<+")) {
       addFacet(elt, ALL, ConstantExpressionDescription.create(true), errors);
     }
     keyword = ADD;
   } else if (keyword.startsWith(">>") || keyword.equals(">-")) {
     // Translation of "container >> item" or "container >- item" to
     // "remove item: item from: container"
     // 08/01/14: Addition of the ">>-" keyword (remove all)
     elt.setKeyword(REMOVE);
     // 20/01/14: Addition of the access [] to remove from the index
     if (expr instanceof Access
         && expr.getOp().equals("[")
         && EGaml.getExprsOf(((Access) expr).getArgs()).size() == 0) {
       addFacet(elt, FROM, convExpr(expr.getLeft(), errors), errors);
       addFacet(elt, INDEX, value, errors);
     } else {
       addFacet(elt, FROM, convExpr(expr, errors), errors);
       addFacet(elt, ITEM, value, errors);
     }
     if (keyword.equals(">>-")) {
       addFacet(elt, ALL, ConstantExpressionDescription.create(true), errors);
     }
     keyword = REMOVE;
   } else if (keyword.equals(EQUATION_OP)) {
     // conversion of left member (either a var or a function)
     IExpressionDescription left = null;
     if (expr instanceof VariableRef) {
       left = new OperatorExpressionDescription(ZERO, convExpr(expr, errors));
     } else {
       left = convExpr(expr, errors);
     }
     addFacet(elt, EQUATION_LEFT, left, errors);
     // Translation of right member
     addFacet(elt, EQUATION_RIGHT, value, errors);
   }
   return keyword;
 }