Пример #1
0
  private ExternalActor createExternalActor(Element element) {
    ExternalActor actor = IrFactory.eINSTANCE.createExternalActor();
    String id = element.getAttribute("id");
    doAnnotations(actor, element);

    addIrObject(id, actor);

    actor.setType((TypeActor) createType(getChild(element, "Type")));

    List<Element> declarations = getChildren(element, "Decl");
    for (Element e : declarations) {
      Variable var = (Variable) createDeclaration(e);
      actor.getDeclarations().add(var);
      if (var.isParameter()) actor.getParameters().add(var);
    }

    List<Element> ports = getChildren(element, "Port");
    for (Element e : ports) {
      Port port = createPort(e);
      if (element.getAttribute("direction").equals("in")) {
        actor.getInputPorts().add(port);
      } else {
        actor.getOutputPorts().add(port);
      }
    }

    return actor;
  }
Пример #2
0
  private Declaration createDeclaration(Element element) {
    String kind = element.getAttribute("kind");
    if (kind.equals("Variable")) {
      Variable variable = IrFactory.eINSTANCE.createVariable();
      variable.setName(element.getAttribute("name"));
      String id = element.getAttribute("id");
      variable.setId(id);
      doAnnotations(variable, element);

      addIrObject(id, variable);

      variable.setScope((Scope) findIrObject(element.getAttribute("scope")));

      if (element.getAttribute("constant").equals("true")) {
        variable.setConstant(true);
      } else {
        variable.setConstant(false);
      }
      if (element.getAttribute("parameter").equals("true")) {
        variable.setParameter(true);
      } else {
        variable.setParameter(false);
      }

      Element typeElement = getChild(element, "Type");
      Type type = createType(typeElement);
      variable.setType(type);

      Element initialValueElement = getChild(element, "InitialValue");
      if (initialValueElement != null) {
        Expression initalValue = createExpression(getChild(initialValueElement, "Expr"));
        variable.setInitValue(initalValue);
      }

      return variable;
    } else if (kind.equals("VariableExternal")) {
      VariableExternal variableExternal = IrFactory.eINSTANCE.createVariableExternal();
      variableExternal.setName(element.getAttribute("name"));
      String id = element.getAttribute("id");
      variableExternal.setId(id);
      doAnnotations(variableExternal, element);

      addIrObject(id, variableExternal);

      variableExternal.setScope((Scope) findIrObject(element.getAttribute("scope")));
      Element typeElement = getChild(element, "Type");
      Type type = createType(typeElement);
      variableExternal.setType(type);

      return variableExternal;
    } else if (kind.equals("VariableImport")) {
      VariableImport variableImport = IrFactory.eINSTANCE.createVariableImport();
      variableImport.setName(element.getAttribute("name"));
      String id = element.getAttribute("id");
      variableImport.setId(id);
      doAnnotations(variableImport, element);

      addIrObject(id, variableImport);

      for (String s : Util.unpackQualifiedName(element.getAttribute("namespace"))) {
        variableImport.getNamespace().add(s);
      }

      return variableImport;
    } else if (kind.equals("TypeImport")) {
      TypeDeclarationImport typeImport = IrFactory.eINSTANCE.createTypeDeclarationImport();
      typeImport.setName(element.getAttribute("name"));
      String id = element.getAttribute("id");
      typeImport.setId(id);
      doAnnotations(typeImport, element);

      addIrObject(id, typeImport);

      for (String s : Util.unpackQualifiedName(element.getAttribute("namespace"))) {
        typeImport.getNamespace().add(s);
      }

      return typeImport;
    } else if (kind.equals("Forward")) {
      ForwardDeclaration forwardDeclaration = IrFactory.eINSTANCE.createForwardDeclaration();
      forwardDeclaration.setName(element.getAttribute("name"));
      String id = element.getAttribute("id");
      forwardDeclaration.setId(id);
      doAnnotations(forwardDeclaration, element);

      addIrObject(id, forwardDeclaration);

      forwardDeclaration.setScope((Scope) findIrObject(element.getAttribute("scope")));
      Element typeElement = getChild(element, "Type");
      Type type = createType(typeElement);
      forwardDeclaration.setType(type);

      // Since the declaration that the ForwardDeclaration
      // is pointing at does not yet exists. That value must
      // be set in a second pass after the whole actor/namespace
      // is evaluted. The id of the actual declaration is stored
      // temprary map.

      forwardDeclarationMap.put(forwardDeclaration, element.getAttribute("forward-id"));

      return forwardDeclaration;
    } else if (kind.equals("Type")) {
      TypeDeclaration typeDeclaration = IrFactory.eINSTANCE.createTypeDeclaration();
      String id = element.getAttribute("id");
      typeDeclaration.setId(id);
      doAnnotations(typeDeclaration, element);

      addIrObject(id, typeDeclaration);

      typeDeclaration.setName(element.getAttribute("name"));

      typeDeclaration.setScope((Scope) findIrObject(element.getAttribute("scope")));

      Element typeElement = getChild(element, "Type");
      Type type = createType(typeElement);
      typeDeclaration.setType(type);

      Element ctorElement = getChild(element, "TypeConstructor");
      TypeConstructor ctor = IrFactory.eINSTANCE.createTypeConstructor();
      ctor.setName(ctorElement.getAttribute("name"));
      ctor.setId(ctorElement.getAttribute("id"));
      doAnnotations(ctor, ctorElement);
      ctor.setScope((Scope) findIrObject(ctorElement.getAttribute("scope")));
      ctor.setTypedef(typeDeclaration);

      typeDeclaration.setConstructor(ctor);

      return typeDeclaration;
    }

    assert (false);
    return null;
  }
 @Override
 public String getName() {
   return mDecl.getName();
 }