示例#1
0
  @Override
  public List<ISpecies> getSelfWithParents() {
    final List<ISpecies> retVal = new ArrayList<ISpecies>();
    retVal.add(this);
    ISpecies currentParent = this.getParentSpecies();
    while (currentParent != null) {
      retVal.add(currentParent);
      currentParent = currentParent.getParentSpecies();
    }

    return retVal;
  }
 private static boolean doesNotDefineAttributes(final String keyword) {
   SymbolProto p = DescriptionFactory.getProto(keyword, null);
   if (p == null) {
     return true;
   }
   int kind = p.getKind();
   return !STATEMENTS_WITH_ATTRIBUTES.contains(kind);
 }
 @Override
 public void setChildren(final List<? extends ISymbol> children) {
   for (final ISymbol c : children) {
     if (c instanceof FsmEnterStatement) {
       enterActions = (FsmEnterStatement) c;
     } else if (c instanceof FsmExitStatement) {
       exitActions = (FsmExitStatement) c;
     } else if (c instanceof FsmTransitionStatement) {
       transitions.add((FsmTransitionStatement) c);
     }
   }
   children.remove(enterActions);
   children.remove(exitActions);
   children.removeAll(transitions);
   transitionsSize = transitions.size();
   super.setChildren(children);
 }
  public static SyntacticModelElement buildSyntacticContents(
      final EObject root, final Set<Diagnostic> errors) {
    if (!(root instanceof Model)) {
      return null;
    }
    ModelImpl m = (ModelImpl) root;
    Object[] imps;
    if (m.eIsSet(GamlPackage.MODEL__IMPORTS)) {
      List<Import> imports = m.getImports();
      imps = new Object[imports.size()];
      for (int i = 0; i < imps.length; i++) {
        URI uri = URI.createURI(imports.get(i).getImportURI(), false);
        imps[i] = uri;
      }
    } else {
      imps = null;
    }

    SyntacticModelElement model =
        (SyntacticModelElement) SyntacticFactory.create(MODEL, m, EGaml.hasChildren(m), imps);
    model.setFacet(NAME, convertToLabel(null, m.getName()));
    convStatements(model, EGaml.getStatementsOf(m), errors);
    return model;
  }
  protected String evaluateTransitions(final IScope scope) throws GamaRuntimeException {
    final IAgent agent = scope.getAgentScope();
    for (int i = 0; i < transitionsSize; i++) {
      final FsmTransitionStatement transition = transitions.get(i);

      if (transition.evaluatesTrueOn(scope)) {
        final String futureState = transition.getName();
        haltOn(scope);
        transition.executeOn(scope);
        scope.setAgentVarValue(agent, STATE, futureState);
        return futureState;
      }
    }
    if (!agent.dead()) {
      scope.saveAllVarValuesIn((Map) agent.getAttribute(STATE_MEMORY));
    }
    return name;
  }
示例#6
0
 @Override
 public void setChildren(final List<? extends ISymbol> children) {
   // First we verify the control architecture
   final IArchitecture control = getArchitecture();
   if (control == null) {
     throw GamaRuntimeException.error(
         "The control of species " + description.getName() + " cannot be computed");
   }
   // Then we classify the children in their categories
   for (final ISymbol s : children) {
     if (s instanceof ISpecies) {
       final ISpecies oneMicroSpecies = (ISpecies) s;
       oneMicroSpecies.setMacroSpecies(this);
       microSpecies.put(oneMicroSpecies.getName(), oneMicroSpecies);
     } else if (s instanceof IVariable) {
       variables.put(s.getName(), (IVariable) s);
     } else if (s instanceof AspectStatement) {
       aspects.put(s.getName(), (AspectStatement) s);
     } else if (s instanceof ActionStatement) {
       if (!s.getDescription().isBuiltIn()) {
         String name = s.getName();
         if (name.equals(initActionName)) {
           isInitOverriden = true;
         } else if (name.equals(stepActionName)) {
           isStepOverriden = true;
         }
       }
       actions.put(s.getName(), (ActionStatement) s);
     } else if (s instanceof UserCommandStatement) {
       userCommands.put(s.getName(), (UserCommandStatement) s);
     } else if (s instanceof IStatement) {
       behaviors.add((IStatement) s); // reflexes, states or tasks
     }
   }
   control.setChildren(behaviors);
   control.verifyBehaviors(this);
 }
示例#7
0
 @Override
 public void dispose() {
   super.dispose();
   for (final IVariable v : variables.values()) {
     v.dispose();
   }
   variables.clear();
   for (final AspectStatement ac : aspects.values()) {
     ac.dispose();
   }
   aspects.clear();
   for (final ActionStatement ac : actions.values()) {
     ac.dispose();
   }
   actions.clear();
   for (final IStatement c : behaviors) {
     c.dispose();
   }
   behaviors.clear();
   macroSpecies = null;
   parentSpecies = null;
   // TODO dispose micro_species first???
   microSpecies.clear();
 }
 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;
 }