use of org.osate.aadl2.DataClassifier in project osate-plugin by sireum.
the class Visitor method processDataType.
public org.sireum.hamr.ir.Component processDataType(DataClassifier f) {
final String name = f.getQualifiedName();
if (datamap.containsKey(name)) {
return datamap.get(name);
}
if (f.getExtended() != null) {
Classifier c = f.getExtended();
String parentName = c.getQualifiedName();
// TODO: add extended classifier name to AIR nodes
// System.out.println(parentName + " >> " + name);
}
/*
* need to use 'getAll...' in order to pickup properties inherited from parent
* since DataClassifier is coming from the declarative model (i.e. isn't flattened)
* javadoc for method:
* A list of the property associations. Property associations from
* an ancestor component classifier will appear before those of any
* descendents.
*/
List<PropertyAssociation> allProperties = VisitorUtil.toIList(f.getAllPropertyAssociations());
List<org.sireum.hamr.ir.Component> subComponents = VisitorUtil.iList();
if (f instanceof DataTypeImpl) {
// do nothing as component types can't have subcomponents
} else if (f instanceof DataImplementation) {
final DataImplementation di = (DataImplementation) f;
// the properties from the data component's type are not inherited by
// the data component's implementation in the declarative model.
// Add the data component type's properties before the data component
// implemention's properties
allProperties = VisitorUtil.addAll(di.getType().getAllPropertyAssociations(), allProperties);
for (Subcomponent subcom : di.getAllSubcomponents()) {
if (!(subcom instanceof DataSubcomponent)) {
throw new RuntimeException("Unexpected data subcomponent: " + subcom.getFullName() + " of type " + subcom.getClass().getSimpleName() + " from " + f.getFullName());
}
DataSubcomponent dsc = (DataSubcomponent) subcom;
final org.sireum.hamr.ir.Name subName = factory.name(VisitorUtil.toIList(dsc.getName()), VisitorUtil.buildPosInfo(dsc));
final List<org.sireum.hamr.ir.Property> fProperties = dsc.getOwnedPropertyAssociations().stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
DataClassifier sct = null;
if (dsc.getDataSubcomponentType() instanceof DataClassifier) {
sct = (DataClassifier) dsc.getDataSubcomponentType();
} else {
if (dsc.getDataSubcomponentType() != null) {
String mesg = "Expecting a DataClassifier for " + dsc.qualifiedName() + " but found something of type " + dsc.getDataSubcomponentType().getClass().getSimpleName() + (dsc.getDataSubcomponentType().hasName() ? " whose name is " + dsc.getDataSubcomponentType().getQualifiedName() : "") + ". This can happen when your model has multiple copies of the same resource.";
throw new RuntimeException(mesg);
}
}
if (sct != null) {
final org.sireum.hamr.ir.Component c = processDataType(sct);
final List<org.sireum.hamr.ir.Property> cProps = VisitorUtil.addAll(VisitorUtil.isz2IList(c.properties()), fProperties);
final AadlASTJavaFactory.ComponentCategory category = AadlASTJavaFactory.ComponentCategory.valueOf(c.category().name());
final org.sireum.hamr.ir.Classifier classifier = c.classifier().nonEmpty() ? c.classifier().get() : null;
final org.sireum.hamr.ir.Component sub = factory.component(subName, category, classifier, VisitorUtil.isz2IList(c.features()), VisitorUtil.isz2IList(c.subComponents()), VisitorUtil.isz2IList(c.connections()), VisitorUtil.isz2IList(c.connectionInstances()), cProps, VisitorUtil.isz2IList(c.flows()), VisitorUtil.isz2IList(c.modes()), VisitorUtil.isz2IList(c.annexes()), VisitorUtil.getUriFragment(sct));
subComponents = VisitorUtil.add(subComponents, sub);
} else {
// type not specified for subcomponent/field
final org.sireum.hamr.ir.Component sub = // name
factory.component(// name
subName, // category
AadlASTJavaFactory.ComponentCategory.Data, // classifier
null, // features
VisitorUtil.iList(), // subComponents
VisitorUtil.iList(), // connections
VisitorUtil.iList(), // connectionInstances
VisitorUtil.iList(), // properties
fProperties, // flows
VisitorUtil.iList(), // modes
VisitorUtil.iList(), // annexes
VisitorUtil.iList(), "");
subComponents = VisitorUtil.add(subComponents, sub);
}
}
} else {
throw new RuntimeException("Unexpected data type: " + f);
}
// NOTE there may be multiple properties associations with the same name if, e.g, a
// data component extends Base_Type::Integer_32 but also adds the property
// Data_Size => 16 bits. So would need to 'findLast' when processing these
// ... so instead remove duplicates? Unless there is a reason why we'd want to
// know the parent values of properties the child shadows
List<PropertyAssociation> uniqueProperties = VisitorUtil.removeShadowedProperties(allProperties);
List<org.sireum.hamr.ir.Property> properties = uniqueProperties.stream().map(op -> buildProperty(op, VisitorUtil.iList())).collect(Collectors.toList());
List<Annex> annexes = new ArrayList<>();
for (AnnexVisitor av : annexVisitors) {
annexes.addAll(av.visit(f, new ArrayList<>()));
}
// this is a hack as we're sticking something from the declarative
// model into a node meant for things from the instance model. Todo
// would be to add a declarative model AIR AST and ...
final org.sireum.hamr.ir.Component c = //
factory.component(// identifier
factory.name(VisitorUtil.iList(), null), // category
AadlASTJavaFactory.ComponentCategory.Data, // features
factory.classifier(name), // features
VisitorUtil.iList(), // connections
subComponents, // connections
VisitorUtil.iList(), // connectionInstances
VisitorUtil.iList(), // properties
properties, // flows
VisitorUtil.iList(), // modes
VisitorUtil.iList(), // annexes
annexes, "");
datamap.put(name, c);
return c;
}
use of org.osate.aadl2.DataClassifier in project osate-plugin by sireum.
the class Visitor method buildFeature.
private org.sireum.hamr.ir.Feature buildFeature(FeatureInstance featureInst, List<String> path) {
final Feature f = featureInst.getFeature();
final List<String> currentPath = VisitorUtil.add(path, featureInst.getName());
org.sireum.hamr.ir.Classifier classifier = null;
if (f.getFeatureClassifier() != null) {
if (f.getFeatureClassifier() instanceof NamedElement) {
if (((NamedElement) f.getFeatureClassifier()).getQualifiedName() != null) {
classifier = factory.classifier(((NamedElement) f.getFeatureClassifier()).getQualifiedName().toString());
} else {
System.out.println("failing here");
}
} else {
throw new RuntimeException("Unexepcted classifier " + f.getFeatureClassifier() + " for feature " + featureInst.getQualifiedName());
}
}
final List<org.sireum.hamr.ir.Property> properties = featureInst.getOwnedPropertyAssociations().stream().map(pa -> buildProperty(pa, currentPath)).collect(Collectors.toList());
AadlASTJavaFactory.FeatureCategory category = null;
switch(featureInst.getCategory()) {
case ABSTRACT_FEATURE:
category = AadlASTJavaFactory.FeatureCategory.AbstractFeature;
break;
case BUS_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.BusAccess;
break;
case DATA_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.DataAccess;
break;
case DATA_PORT:
category = AadlASTJavaFactory.FeatureCategory.DataPort;
break;
case EVENT_PORT:
category = AadlASTJavaFactory.FeatureCategory.EventPort;
break;
case EVENT_DATA_PORT:
category = AadlASTJavaFactory.FeatureCategory.EventDataPort;
break;
case FEATURE_GROUP:
category = AadlASTJavaFactory.FeatureCategory.FeatureGroup;
break;
case PARAMETER:
category = AadlASTJavaFactory.FeatureCategory.Parameter;
break;
case SUBPROGRAM_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.SubprogramAccess;
break;
case SUBPROGRAM_GROUP_ACCESS:
category = AadlASTJavaFactory.FeatureCategory.SubprogramAccessGroup;
break;
default:
throw new RuntimeException("Unexpected category: " + featureInst.getCategory());
}
switch(featureInst.getCategory()) {
case DATA_ACCESS:
case DATA_PORT:
case EVENT_DATA_PORT:
case PARAMETER:
if (f.getClassifier() instanceof DataClassifier) {
processDataType((DataClassifier) f.getClassifier());
}
// do nothing
default:
}
org.sireum.hamr.ir.Name identifier = factory.name(currentPath, VisitorUtil.buildPosInfo(featureInst.getInstantiatedObjects().get(0)));
final List<FeatureInstance> featureInstances = featureInst.getFeatureInstances();
if (featureInstances.isEmpty()) {
if (f instanceof AccessImpl) {
final AccessImpl accessImpl = (AccessImpl) f;
final AadlASTJavaFactory.AccessType accessType = accessImpl.getKind() == AccessType.PROVIDES ? AadlASTJavaFactory.AccessType.Provides : AadlASTJavaFactory.AccessType.Requires;
AadlASTJavaFactory.AccessCategory accessCategory = null;
switch(accessImpl.getCategory()) {
case BUS:
accessCategory = AadlASTJavaFactory.AccessCategory.Bus;
break;
case DATA:
accessCategory = AadlASTJavaFactory.AccessCategory.Data;
break;
case SUBPROGRAM:
accessCategory = AadlASTJavaFactory.AccessCategory.Subprogram;
break;
case SUBPROGRAM_GROUP:
accessCategory = AadlASTJavaFactory.AccessCategory.SubprogramGroup;
break;
case VIRTUAL_BUS:
accessCategory = AadlASTJavaFactory.AccessCategory.VirtualBus;
break;
}
return factory.featureAccess(identifier, category, classifier, accessType, accessCategory, properties, VisitorUtil.getUriFragment(featureInst));
} else if (f instanceof DirectedFeatureImpl) {
final AadlASTJavaFactory.Direction direction = handleDirection(featureInst.getDirection());
return factory.featureEnd(identifier, direction, category, classifier, properties, VisitorUtil.getUriFragment(featureInst));
} else {
throw new RuntimeException("Not expecting feature: " + featureInst);
}
} else {
final boolean isInverse = ((FeatureGroupImpl) f).isInverse();
final List<org.sireum.hamr.ir.Feature> features = featureInstances.stream().map(fi -> buildFeature(fi, currentPath)).collect(Collectors.toList());
return factory.featureGroup(identifier, features, isInverse, category, properties, VisitorUtil.getUriFragment(featureInst));
}
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUnparser method initSwitches.
/**
* Specific aadlba switch to unparse components
*/
protected void initSwitches() {
aadlbaSwitch = new AadlBaSwitch<String>() {
/**
* Top-level method to unparse "behavior_specification"
* annexsubclause
*/
// public String caseAnnexSubclause(AnnexSubclause object) {
// //FIXME : TODO : update location reference
//
// process((BehaviorAnnex) object);
//
// return DONE;
// }
/**
* Unparse behaviorannex
*/
@Override
public String caseBehaviorAnnex(BehaviorAnnex object) {
// DB: Improve code formatting
aadlbaText.addOutputNewline("");
// FIXME : TODO : update location reference
if (object.isSetVariables()) {
aadlbaText.addOutputNewline("variables");
aadlbaText.incrementIndent();
processEList(object.getVariables());
aadlbaText.decrementIndent();
}
if (object.isSetStates()) {
aadlbaText.addOutputNewline("states");
aadlbaText.incrementIndent();
processEList(object.getStates());
aadlbaText.decrementIndent();
}
if (object.isSetTransitions()) {
aadlbaText.addOutputNewline("transitions");
aadlbaText.incrementIndent();
processEList(object.getTransitions());
aadlbaText.decrementIndent();
}
return DONE;
}
/**
* Unparse behaviorvariable
*/
@Override
public String caseBehaviorVariable(BehaviorVariable object) {
// FIXME : TODO : update location reference
aadlbaText.addOutput(object.getName());
for (ArrayDimension ad : object.getArrayDimensions()) {
aadlbaText.addOutput("[");
if (ad instanceof DeclarativeArrayDimension) {
DeclarativeArrayDimension dad = (DeclarativeArrayDimension) ad;
process(dad.getDimension());
} else if (ad instanceof ArrayDimension) {
aadlbaText.addOutput(Long.toString(ad.getSize().getSize()));
}
aadlbaText.addOutput("]");
}
aadlbaText.addOutput(" : ");
if (object.getDataClassifier() instanceof QualifiedNamedElement) {
QualifiedNamedElement qn = (QualifiedNamedElement) object.getDataClassifier();
aadlbaText.addOutput(getNamespace(qn));
process(qn);
} else if (object.getDataClassifier() instanceof DataClassifier) {
aadlbaText.addOutput(object.getDataClassifier().getQualifiedName());
}
aadlbaText.addOutputNewline(";");
return DONE;
}
private String getNamespace(final QualifiedNamedElement qn) {
final Identifier baNameSpace = qn.getBaNamespace();
final StringBuilder nameSpace = new StringBuilder();
if (baNameSpace != null && !Strings.isNullOrEmpty(baNameSpace.getId())) {
nameSpace.append(baNameSpace.getId()).append("::");
}
return nameSpace.toString();
}
/**
* Unparse behaviorstate
*/
@Override
public String caseBehaviorState(BehaviorState object) {
// FIXME : TODO : update location reference
aadlbaText.addOutput(object.getName());
aadlbaText.addOutput(" : ");
if (object.isInitial()) {
aadlbaText.addOutput("initial ");
}
if (object.isComplete()) {
aadlbaText.addOutput("complete ");
}
if (object.isFinal()) {
aadlbaText.addOutput("final ");
}
aadlbaText.addOutputNewline("state;");
return DONE;
}
/**
* Unparse behaviortransition
*/
@Override
public String caseBehaviorTransition(BehaviorTransition object) {
// FIXME : TODO : update location reference
String tid = object.getName();
Long num = object.getPriority();
if (tid != null) {
aadlbaText.addOutput(tid);
if (num != AadlBaVisitors.DEFAULT_TRANSITION_PRIORITY) {
// numeral
aadlbaText.addOutput(" [");
aadlbaText.addOutput(String.valueOf(num));
aadlbaText.addOutput("]");
}
aadlbaText.addOutput(" : ");
}
if (object.getSourceState() != null) {
aadlbaText.addOutput(object.getSourceState().getName());
} else if (object instanceof DeclarativeBehaviorTransition) {
DeclarativeBehaviorTransition dbt = (DeclarativeBehaviorTransition) object;
for (Identifier id : dbt.getSrcStates()) {
aadlbaText.addOutput(id.getId());
if (dbt.getSrcStates().get(dbt.getSrcStates().size() - 1) != id) {
aadlbaText.addOutput(",");
}
}
}
aadlbaText.addOutput(" -[");
process(object.getCondition());
aadlbaText.addOutput("]-> ");
if (object.getDestinationState() != null) {
aadlbaText.addOutput(object.getDestinationState().getName());
} else if (object instanceof DeclarativeBehaviorTransition) {
DeclarativeBehaviorTransition dbt = (DeclarativeBehaviorTransition) object;
aadlbaText.addOutput(dbt.getDestState().getId());
}
if (object.getActionBlock() != null) {
aadlbaText.addOutput(" ");
process(object.getActionBlock());
}
aadlbaText.addOutputNewline(";");
return DONE;
}
@Override
public String caseExecutionTimeoutCatch(ExecutionTimeoutCatch object) {
aadlbaText.addOutput("timeout");
return DONE;
}
@Override
public String caseOtherwise(Otherwise object) {
aadlbaText.addOutput("otherwise");
return DONE;
}
/**
* Unparse dispatchcondition
*/
@Override
public String caseDispatchCondition(DispatchCondition object) {
// FIXME : TODO : update location reference
aadlbaText.addOutput("on dispatch");
if (object.getDispatchTriggerCondition() != null) {
aadlbaText.addOutput(" ");
process(object.getDispatchTriggerCondition());
}
if (object.isSetFrozenPorts()) {
aadlbaText.addOutput(" frozen ");
processEList(object.getFrozenPorts(), ", ");
}
return DONE;
}
@Override
public String caseDispatchTriggerConditionStop(DispatchTriggerConditionStop object) {
aadlbaText.addOutput("stop");
return DONE;
}
@Override
public String caseDispatchRelativeTimeout(DispatchRelativeTimeout object) {
aadlbaText.addOutput("timeout ");
return DONE;
}
@Override
public String caseCompletionRelativeTimeout(CompletionRelativeTimeout object) {
aadlbaText.addOutput("timeout ");
caseBehaviorTime(object);
return DONE;
}
@Override
public String caseDispatchTriggerLogicalExpression(DispatchTriggerLogicalExpression object) {
processEList(object.getDispatchConjunctions(), " or ");
return DONE;
}
@Override
public String caseDispatchConjunction(DispatchConjunction object) {
processEList(object.getDispatchTriggers(), " and ");
return DONE;
}
@Override
public String caseBehaviorActionBlock(BehaviorActionBlock object) {
aadlbaText.addOutputNewline("{");
aadlbaText.incrementIndent();
// aadlbaText.addOutput("{");
process(object.getContent());
aadlbaText.decrementIndent();
aadlbaText.addOutputNewline("");
aadlbaText.addOutput("}");
if (object.getTimeout() != null) {
aadlbaText.addOutput(" timeout ");
process(object.getTimeout());
}
return DONE;
}
@Override
public String caseBehaviorActionSequence(BehaviorActionSequence object) {
// DB: Indentation problem when using \n direcly
processEList(object.getActions(), ";", true);
// processEList(object.getActions(), ";\n");
return DONE;
}
@Override
public String caseBehaviorActionSet(BehaviorActionSet object) {
// DB: Indentation problem when using \n direcly
processEList(object.getActions(), " &", true);
// processEList(object.getActions(), " &\n");
return DONE;
}
/**
* Unparse ifstatement
*/
@Override
public String caseIfStatement(IfStatement object) {
// FIXME : TODO : update location reference
boolean hasToOutputTerminator = true;
if (object.isElif()) {
aadlbaText.addOutputNewline("");
aadlbaText.addOutput("elsif (");
hasToOutputTerminator = false;
} else {
aadlbaText.addOutput("if (");
hasToOutputTerminator = true;
}
process(object.getLogicalValueExpression());
aadlbaText.addOutputNewline(")");
aadlbaText.incrementIndent();
process(object.getBehaviorActions());
aadlbaText.decrementIndent();
if (object.getElseStatement() != null) {
process(object.getElseStatement());
}
if (hasToOutputTerminator) {
aadlbaText.addOutputNewline("");
aadlbaText.addOutput("end if");
}
return DONE;
}
@Override
public String caseElseStatement(ElseStatement object) {
aadlbaText.addOutputNewline("");
aadlbaText.addOutputNewline("else");
aadlbaText.incrementIndent();
process(object.getBehaviorActions());
aadlbaText.decrementIndent();
return DONE;
}
/**
* Unparse fororforallstatement
*/
@Override
public String caseForOrForAllStatement(ForOrForAllStatement object) {
// FIXME : TODO : update location reference
if (object.isForAll()) {
aadlbaText.addOutput("forall (");
} else {
aadlbaText.addOutput("for (");
}
process(object.getIterativeVariable());
aadlbaText.addOutput(" in ");
process(object.getIteratedValues());
aadlbaText.addOutputNewline(") {");
// aadlbaText.addOutputNewline("{");
aadlbaText.incrementIndent();
process(object.getBehaviorActions());
aadlbaText.decrementIndent();
aadlbaText.addOutputNewline("");
aadlbaText.addOutput("}");
return DONE;
}
@Override
public String caseIterativeVariable(IterativeVariable iv) {
aadlbaText.addOutput(iv.getName());
aadlbaText.addOutput(" : ");
// DB: Use qualified name when classifier is declared outside the package
final DataClassifier dataClass = iv.getDataClassifier();
final String dataClassName;
if (dataClass.getElementRoot() == iv.getElementRoot()) {
dataClassName = dataClass.getName();
} else {
dataClassName = dataClass.getQualifiedName();
}
aadlbaText.addOutput(dataClassName);
return DONE;
}
@Override
public String caseWhileOrDoUntilStatement(WhileOrDoUntilStatement object) {
if (object.isDoUntil()) {
return caseDoUntilStatement(object);
} else {
return caseWhileStatement(object);
}
}
/**
* Unparse whilestatement
*/
public String caseWhileStatement(WhileOrDoUntilStatement object) {
// FIXME : TODO : update location reference
aadlbaText.addOutput("while (");
process(object.getLogicalValueExpression());
aadlbaText.addOutputNewline(") {");
// aadlbaText.addOutputNewline("{");
aadlbaText.incrementIndent();
process(object.getBehaviorActions());
aadlbaText.decrementIndent();
aadlbaText.addOutputNewline("");
aadlbaText.addOutputNewline("}");
return DONE;
}
/**
* Unparse dountilstatement
*/
public String caseDoUntilStatement(WhileOrDoUntilStatement object) {
// FIXME : TODO : update location reference
aadlbaText.addOutputNewline("do");
process(object.getBehaviorActions());
aadlbaText.addOutputNewline("");
aadlbaText.addOutput("until (");
process(object.getLogicalValueExpression());
aadlbaText.addOutputNewline(")");
return DONE;
}
/**
* Unparse integerrange
*/
@Override
public String caseIntegerRange(IntegerRange object) {
// FIXME : TODO : update location reference
process(object.getLowerIntegerValue());
aadlbaText.addOutput(" .. ");
process(object.getUpperIntegerValue());
return DONE;
}
/**
* Unparse timedaction
*/
@Override
public String caseTimedAction(TimedAction object) {
aadlbaText.addOutput("computation (");
process(object.getLowerTime());
if (object.getUpperTime() != null) {
aadlbaText.addOutput(" .. ");
process(object.getUpperTime());
}
aadlbaText.addOutput(")");
if (object.isSetProcessorClassifier()) {
aadlbaText.addOutput(" in binding (");
processEList(object.getProcessorClassifier(), ", ", object, false);
aadlbaText.addOutput(")");
}
return DONE;
}
/**
* Unparse assignmentaction
*/
@Override
public String caseAssignmentAction(AssignmentAction object) {
// FIXME : TODO : update location reference
process(object.getTarget());
aadlbaText.addOutput(" := ");
process(object.getValueExpression());
return DONE;
}
@Override
public String caseAny(Any object) {
aadlbaText.addOutput("any");
return DONE;
}
@Override
public String caseElementHolder(ElementHolder el) {
if (el instanceof Reference) {
return processReference((Reference) el);
}
Element refContainer = Aadl2Visitors.getContainingPackageSection(el.getElement());
Element holderPackageOrPropertySet = Aadl2Visitors.getContainingPackageSection(el);
if (refContainer != null && holderPackageOrPropertySet != null && false == holderPackageOrPropertySet.equals(refContainer) && false == (el instanceof DataSubcomponentHolder)) {
StringBuilder sb = new StringBuilder(el.getElement().getQualifiedName());
String prefix = sb.substring(0, sb.lastIndexOf("::") + 2);
aadlbaText.addOutput(prefix);
}
if (el instanceof GroupableElement) {
GroupableElement ge = (GroupableElement) el;
if (ge.isSetGroupHolders()) {
processEList(ge.getGroupHolders(), ".");
aadlbaText.addOutput(".");
}
}
aadlbaText.addOutput(el.getElement().getName());
if (el instanceof IndexableElement) {
IndexableElement ie = (IndexableElement) el;
if (ie.isSetArrayIndexes()) {
caseArrayIndex(ie.getArrayIndexes());
}
}
return DONE;
}
private String processReference(Reference ref) {
for (ArrayableIdentifier id : ref.getIds()) {
aadlbaText.addOutput(id.getId());
caseArrayIndex(id.getArrayIndexes());
if (id != ref.getIds().get(ref.getIds().size() - 1)) {
aadlbaText.addOutput(".");
}
}
return DONE;
}
private String processCommAction(CommAction object) {
process(object.getReference());
if (object.isLock()) {
aadlbaText.addOutput("!<");
} else if (object.isUnlock()) {
aadlbaText.addOutput("!>");
} else if (object.isPortDequeue()) {
aadlbaText.addOutput(" ?");
} else {
aadlbaText.addOutput(" !");
}
if (object.isSetParameters() == true) {
aadlbaText.addOutput(" (");
processEList(object.getParameters(), ",");
aadlbaText.addOutput(")");
return DONE;
} else if (object.getTarget() != null) {
aadlbaText.addOutput(" (");
process(object.getTarget());
aadlbaText.addOutput(")");
return DONE;
}
return DONE;
}
/**
* Unparse arrayindex
*/
public String caseArrayIndex(EList<IntegerValue> object) {
// FIXME : TODO : update location reference
for (IntegerValue iv : object) {
aadlbaText.addOutput("[");
process(iv);
aadlbaText.addOutput("]");
}
return DONE;
}
/**
* Unparse datacomponentreference
*/
@Override
public String caseDataComponentReference(DataComponentReference object) {
// FIXME : TODO : update location reference
processEList(object.getData(), ".");
return DONE;
}
@Override
public String defaultCase(EObject object) {
if (object instanceof CommAction) {
return processCommAction((CommAction) object);
} else if (object instanceof Reference) {
return processReference((Reference) object);
} else if (object instanceof QualifiedNamedElement) {
QualifiedNamedElement qn = (QualifiedNamedElement) object;
aadlbaText.addOutput(qn.getBaName().getId());
} else if (object instanceof org.osate.ba.declarative.NamedValue) {
org.osate.ba.declarative.NamedValue nv = (org.osate.ba.declarative.NamedValue) object;
process(nv.getReference());
if (nv.isCount()) {
aadlbaText.addOutput("' count");
}
if (nv.isFresh()) {
aadlbaText.addOutput("' fresh");
}
if (nv.isDequeue()) {
aadlbaText.addOutput(" ?");
}
} else if (object instanceof DeclarativePropertyReference) {
DeclarativePropertyReference dpr = (DeclarativePropertyReference) object;
if (dpr.getQualifiedName().getBaName().getId().isEmpty()) {
aadlbaText.addOutput("#");
}
aadlbaText.addOutput(dpr.getQualifiedName().getBaNamespace().getId());
aadlbaText.addOutput("::");
if (false == dpr.getQualifiedName().getBaName().getId().isEmpty()) {
aadlbaText.addOutput(dpr.getQualifiedName().getBaName().getId());
aadlbaText.addOutput("#");
}
processEList(dpr.getPropertyNames(), ".");
} else if (object instanceof DeclarativePropertyName) {
DeclarativePropertyName dpn = (DeclarativePropertyName) object;
aadlbaText.addOutput(dpn.getPropertyName().getId());
// field
process(dpn.getField());
// indexes
caseArrayIndex(dpn.getIndexes());
}
return DONE;
}
@Override
public String caseSubprogramCallAction(SubprogramCallAction object) {
if (object.getProxy() != null) {
process(object.getProxy());
aadlbaText.addOutput(".");
}
process(object.getSubprogram());
aadlbaText.addOutput(" !");
if (object.isSetParameterLabels()) {
aadlbaText.addOutput(" (");
processEList(object.getParameterLabels(), ", ");
aadlbaText.addOutput(")");
}
return DONE;
}
@Override
public String casePortSendAction(PortSendAction object) {
process(object.getPort());
aadlbaText.addOutput(" !");
if (object.getValueExpression() != null) {
aadlbaText.addOutput(" (");
process(object.getValueExpression());
aadlbaText.addOutput(")");
}
return DONE;
}
@Override
public String casePortFreezeAction(PortFreezeAction object) {
return casePortActionOrValue(object, " >>");
}
@Override
public String casePortDequeueAction(PortDequeueAction object) {
process(object.getPort());
aadlbaText.addOutput(" ?");
if (object.getTarget() != null) {
aadlbaText.addOutput(" (");
process(object.getTarget());
aadlbaText.addOutput(")");
}
return DONE;
}
@Override
public String caseLockAction(LockAction object) {
return caseSharedDataAction(object, "!<");
}
@Override
public String caseUnlockAction(UnlockAction object) {
return caseSharedDataAction(object, "!>");
}
public String caseSharedDataAction(SharedDataAction object, String token) {
if (object.getDataAccess() != null) {
process(object.getDataAccess());
aadlbaText.addOutput(" ");
} else {
aadlbaText.addOutput("*");
}
aadlbaText.addOutput(token);
return DONE;
}
/**
* Unparse behaviortime
*/
@Override
public String caseBehaviorTime(BehaviorTime object) {
// FIXME : TODO : update location reference
process(object.getIntegerValue());
aadlbaText.addOutput(" ");
if (object.getUnit() != null) {
aadlbaText.addOutput(object.getUnit().getName());
} else {
if (object instanceof DeclarativeTime) {
DeclarativeTime dt = (DeclarativeTime) object;
aadlbaText.addOutput(dt.getUnitId().getId());
}
}
return DONE;
}
@Override
public String casePortDequeueValue(PortDequeueValue object) {
return casePortActionOrValue(object, " ?");
}
@Override
public String casePortCountValue(PortCountValue object) {
return casePortActionOrValue(object, "' count");
}
@Override
public String casePortFreshValue(PortFreshValue object) {
return casePortActionOrValue(object, "' fresh");
}
public String casePortActionOrValue(PortHolder object, String token) {
caseElementHolder(object);
aadlbaText.addOutput(token);
return DONE;
}
/**
* Unparse booleanliteral
*/
@Override
public String caseBehaviorBooleanLiteral(BehaviorBooleanLiteral object) {
// FIXME : TODO : update location reference
if (object.isValue()) {
aadlbaText.addOutput("true");
} else {
aadlbaText.addOutput("false");
}
return DONE;
}
/**
* Unparse stringliteral
*/
@Override
public String caseBehaviorStringLiteral(BehaviorStringLiteral object) {
// FIXME : TODO : update location reference
// DB: Manage adding double quotes
aadlbaText.addOutput(doubleQuoteString(object.getValue()));
return DONE;
}
@Override
public String caseBehaviorRealLiteral(BehaviorRealLiteral object) {
aadlbaText.addOutput(String.valueOf(object.getValue()));
return DONE;
}
@Override
public String caseBehaviorIntegerLiteral(BehaviorIntegerLiteral object) {
aadlbaText.addOutput(Long.toString(object.getValue()));
return DONE;
}
/**
* Unparse valueexpression
*/
@Override
public String caseValueExpression(ValueExpression object) {
// FIXME : TODO : update location reference
Iterator<Relation> itRel = object.getRelations().iterator();
process(itRel.next());
if (object.isSetLogicalOperators()) {
Iterator<LogicalOperator> itOp = object.getLogicalOperators().iterator();
while (itRel.hasNext()) {
LogicalOperator lo = itOp.next();
if (lo != LogicalOperator.NONE) {
aadlbaText.addOutput(" " + lo.getLiteral() + " ");
}
process(itRel.next());
}
}
return DONE;
}
/**
* Unparse relation
*/
@Override
public String caseRelation(Relation object) {
// FIXME : TODO : update location reference
process(object.getFirstExpression());
if (object.getSecondExpression() != null) {
if (object.getRelationalOperator() != RelationalOperator.NONE) {
aadlbaText.addOutput(" " + object.getRelationalOperator().getLiteral() + " ");
}
process(object.getSecondExpression());
}
return DONE;
}
/**
* Unparse simpleexpression
*/
@Override
public String caseSimpleExpression(SimpleExpression object) {
// FIXME : TODO : update location reference
if (object.isSetUnaryAddingOperator() && object.getUnaryAddingOperator() != UnaryAddingOperator.NONE) {
aadlbaText.addOutput(object.getUnaryAddingOperator().getLiteral());
}
Iterator<Term> itTerm = object.getTerms().iterator();
process(itTerm.next());
if (object.isSetBinaryAddingOperators()) {
Iterator<BinaryAddingOperator> itOp = object.getBinaryAddingOperators().iterator();
while (itTerm.hasNext()) {
BinaryAddingOperator bao = itOp.next();
if (bao != BinaryAddingOperator.NONE) {
aadlbaText.addOutput(" " + bao.getLiteral() + " ");
}
process(itTerm.next());
}
}
return DONE;
}
/**
* Unparse term
*/
@Override
public String caseTerm(Term object) {
// FIXME : TODO : update location reference
Iterator<Factor> itFact = object.getFactors().iterator();
process(itFact.next());
if (object.isSetMultiplyingOperators()) {
Iterator<MultiplyingOperator> itOp = object.getMultiplyingOperators().iterator();
while (itFact.hasNext()) {
MultiplyingOperator mo = itOp.next();
if (mo != MultiplyingOperator.NONE) {
aadlbaText.addOutput(" " + mo.getLiteral() + " ");
}
process(itFact.next());
}
}
return DONE;
}
/**
* Unparse factor
*/
@Override
public String caseFactor(Factor object) {
// FIXME : TODO : update location reference
if (object.isSetUnaryNumericOperator() || object.isSetUnaryBooleanOperator()) {
Enumerator e = null;
if (object.isSetUnaryNumericOperator()) {
e = object.getUnaryNumericOperator();
if (e != UnaryNumericOperator.NONE) {
aadlbaText.addOutput(e.getLiteral() + " ");
}
} else if (object.isSetUnaryBooleanOperator()) {
e = object.getUnaryBooleanOperator();
if (e != UnaryBooleanOperator.NONE) {
aadlbaText.addOutput(e.getLiteral() + " ");
}
}
}
if (object.getFirstValue() instanceof ValueExpression) {
aadlbaText.addOutput("(");
process(object.getFirstValue());
aadlbaText.addOutput(")");
} else {
process(object.getFirstValue());
}
if (object.isSetBinaryNumericOperator()) {
BinaryNumericOperator bno = object.getBinaryNumericOperator();
if (bno != BinaryNumericOperator.NONE) {
aadlbaText.addOutput(" " + bno.getLiteral() + " ");
}
if (object.getSecondValue() instanceof ValueExpression) {
aadlbaText.addOutput("(");
process(object.getSecondValue());
aadlbaText.addOutput(")");
} else {
process(object.getSecondValue());
}
}
return DONE;
}
@Override
public String caseBehaviorPropertyConstant(BehaviorPropertyConstant object) {
aadlbaText.addOutput("#");
if (object.getPropertySet() != null) {
aadlbaText.addOutput(object.getPropertySet().getQualifiedName());
aadlbaText.addOutput("::");
}
aadlbaText.addOutput(object.getProperty().getName());
return DONE;
}
@Override
public String casePropertySetPropertyReference(PropertySetPropertyReference object) {
aadlbaText.addOutput("#");
if (object.getPropertySet() != null) {
aadlbaText.addOutput(object.getPropertySet().getQualifiedName());
aadlbaText.addOutput("::");
}
processEList(object.getProperties(), ".");
return DONE;
}
@Override
public String caseClassifierPropertyReference(ClassifierPropertyReference object) {
org.osate.aadl2.Classifier c = object.getClassifier();
process(c, object);
aadlbaText.addOutput("#");
processEList(object.getProperties(), ".");
return DONE;
}
@Override
public String caseClassifierFeaturePropertyReference(ClassifierFeaturePropertyReference object) {
process(object.getComponent());
aadlbaText.addOutput("#");
processEList(object.getProperties(), ".");
return DONE;
}
@Override
public String casePropertyNameHolder(PropertyNameHolder pnh) {
PropertyElementHolder peh = pnh.getProperty();
Element el = peh.getElement();
if (el instanceof NamedElement) {
aadlbaText.addOutput(((NamedElement) el).getName());
} else if (el instanceof PropertyAssociation) {
aadlbaText.addOutput(((PropertyAssociation) el).getProperty().getName());
} else {
String tmp = unparse((PropertyExpression) el);
aadlbaText.addOutput(tmp);
}
if (pnh.getField() != null) {
aadlbaText.addOutput(".");
process(pnh.getField());
} else if (peh.isSetArrayIndexes()) {
caseArrayIndex(peh.getArrayIndexes());
}
return DONE;
}
@Override
public String caseUpperBound(UpperBound object) {
aadlbaText.addOutput("upper_bound");
return DONE;
}
@Override
public String caseLowerBound(LowerBound object) {
aadlbaText.addOutput("lower_bound");
return DONE;
}
};
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method getDataClassifier.
/**
* Returns the DataClassifier of the element binded to the given
* Value object. A target instance can be given to this method as
* Target instance can be cast into ValueVariable reference.
* <BR><BR>
* Notes: <BR><BR>
* <BR>_ ValueVariable : {@link #getClassifier(Element, Classifier)}
* to see the restrictions.
* <BR>_ ValueConstant : Property constant and property reference are not supported:
* returns {@code null}.
* <BR><BR>
*
* @param v the given Value object
* @param parentContainer only for AADLBA declarative objects which have no
* parent set, yet
* @return the binded component's DataClassifier object or {@code null} for
* the ValueConstant objects and for the Abstract components objects.
* @exception UnsupportedOperationException for unsupported binded
* object types.
*/
public static DataClassifier getDataClassifier(Value v, ComponentClassifier parentContainer) {
Classifier result = null;
if (v instanceof ValueVariable) {
// Either ElementHolder or DataComponentReference object.
Element el = null;
if (v instanceof ElementHolder) {
el = ((ElementHolder) v).getElement();
} else // DataComponentReference case.
{
DataComponentReference dcr = (DataComponentReference) v;
DataHolder lastElement = dcr.getData().get(dcr.getData().size() - 1);
el = lastElement.getElement();
}
if (parentContainer == null) {
parentContainer = (ComponentClassifier) v.getContainingClassifier();
}
result = getClassifier(el, parentContainer);
} else // Property constant and property reference are not supported.
{
result = null;
}
if (result instanceof DataClassifier) {
return (DataClassifier) result;
} else // Abstract components case.
{
return null;
}
}
use of org.osate.aadl2.DataClassifier in project osate2 by osate.
the class AadlBaUtils method getFeatureType.
/**
* Analyze the given AADL Osate element and return its enumeration type.
*
* It's an improved version of Osate2 org.osate.parser.AadlSemanticCheckSwitch#getFeatureType
*
* @param el the given AADL Osate element
* @return the given AADL Osate element's type
* @exception UnsupportedOperationException for the unsupported types
*/
/*
* <copyright>
* Copyright 2009 by Carnegie Mellon University, all rights reserved.
*
* Use of the Open Source AADL Tool Environment (OSATE) is subject to the terms of the license set forth
* at http://www.eclipse.org/legal/cpl-v10.html.
*
* NO WARRANTY
*
* ANY INFORMATION, MATERIALS, SERVICES, INTELLECTUAL PROPERTY OR OTHER PROPERTY OR RIGHTS GRANTED OR PROVIDED BY
* CARNEGIE MELLON UNIVERSITY PURSUANT TO THIS LICENSE (HEREINAFTER THE "DELIVERABLES") ARE ON AN "AS-IS" BASIS.
* CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED AS TO ANY MATTER INCLUDING,
* BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, INFORMATIONAL CONTENT,
* NONINFRINGEMENT, OR ERROR-FREE OPERATION. CARNEGIE MELLON UNIVERSITY SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR
* CONSEQUENTIAL DAMAGES, SUCH AS LOSS OF PROFITS OR INABILITY TO USE SAID INTELLECTUAL PROPERTY, UNDER THIS LICENSE,
* REGARDLESS OF WHETHER SUCH PARTY WAS AWARE OF THE POSSIBILITY OF SUCH DAMAGES. LICENSEE AGREES THAT IT WILL NOT
* MAKE ANY WARRANTY ON BEHALF OF CARNEGIE MELLON UNIVERSITY, EXPRESS OR IMPLIED, TO ANY PERSON CONCERNING THE
* APPLICATION OF OR THE RESULTS TO BE OBTAINED WITH THE DELIVERABLES UNDER THIS LICENSE.
*
* Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie Mellon University, its trustees, officers,
* employees, and agents from all claims or demands made against them (and any related losses, expenses, or
* attorney's fees) arising out of, or relating to Licensee's and/or its sub licensees' negligent use or willful
* misuse of or negligent conduct or willful misconduct regarding the Software, facilities, or other rights or
* assistance granted by Carnegie Mellon University under this License, including, but not limited to, any claims of
* product liability, personal injury, death, damage to property, or violation of any laws or regulations.
*
* Carnegie Mellon University Software Engineering Institute authored documents are sponsored by the U.S. Department
* of Defense under Contract F19628-00-C-0003. Carnegie Mellon University retains copyrights in all material produced
* under this contract. The U.S. Government retains a non-exclusive, royalty-free license to publish or reproduce these
* documents, or allow others to do so, for U.S. Government purposes only pursuant to the copyright license
* under the contract clause at 252.227.7013.
* </copyright>
*/
public static org.osate.ba.aadlba.FeatureType getFeatureType(Element el) {
if (el instanceof DataPort) {
switch(((DataPort) el).getDirection()) {
case IN:
return FeatureType.IN_DATA_PORT;
case OUT:
return FeatureType.OUT_DATA_PORT;
case IN_OUT:
return FeatureType.IN_OUT_DATA_PORT;
}
} else if (el instanceof EventPort) {
switch(((EventPort) el).getDirection()) {
case IN:
return FeatureType.IN_EVENT_PORT;
case OUT:
return FeatureType.OUT_EVENT_PORT;
case IN_OUT:
return FeatureType.IN_OUT_EVENT_PORT;
}
} else if (el instanceof EventDataPort) {
switch(((EventDataPort) el).getDirection()) {
case IN:
return FeatureType.IN_EVENT_DATA_PORT;
case OUT:
return FeatureType.OUT_EVENT_DATA_PORT;
case IN_OUT:
return FeatureType.IN_OUT_EVENT_DATA_PORT;
}
} else if (el instanceof FeatureGroup) {
return FeatureType.FEATURE_GROUP;
} else if (el instanceof DataAccess) {
switch(((DataAccess) el).getKind()) {
case PROVIDES:
return FeatureType.PROVIDES_DATA_ACCESS;
case REQUIRES:
return FeatureType.REQUIRES_DATA_ACCESS;
}
} else if (el instanceof SubprogramAccess) {
switch(((SubprogramAccess) el).getKind()) {
case PROVIDES:
return FeatureType.PROVIDES_SUBPROGRAM_ACCESS;
case REQUIRES:
return FeatureType.REQUIRES_SUBPROGRAM_ACCESS;
}
} else if (el instanceof SubprogramGroupAccess) {
switch(((SubprogramGroupAccess) el).getKind()) {
case PROVIDES:
return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
case REQUIRES:
return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
}
} else if (el instanceof BusAccess) {
switch(((BusAccess) el).getKind()) {
case PROVIDES:
return FeatureType.PROVIDES_BUS_ACCESS;
case REQUIRES:
return FeatureType.REQUIRES_BUS_ACCESS;
}
} else if (el instanceof AbstractFeature) {
return FeatureType.ABSTRACT_FEATURE;
} else if (el instanceof Parameter) {
switch(((Parameter) el).getDirection()) {
case IN:
return FeatureType.IN_PARAMETER;
case OUT:
return FeatureType.OUT_PARAMETER;
case IN_OUT:
return FeatureType.IN_OUT_PARAMETER;
}
} else if (el instanceof Prototype) {
if (el instanceof ComponentPrototype) {
switch(el.eClass().getClassifierID()) {
case Aadl2Package.SUBPROGRAM_PROTOTYPE:
return FeatureType.SUBPROGRAM_PROTOTYPE;
case Aadl2Package.SUBPROGRAM_GROUP_PROTOTYPE:
return FeatureType.SUBPROGRAM_GROUP_PROTOTYPE;
case Aadl2Package.THREAD_PROTOTYPE:
return FeatureType.THREAD_PROTOTYPE;
case Aadl2Package.THREAD_GROUP_PROTOTYPE:
return FeatureType.THREAD_GROUP_PROTOTYPE;
default:
return FeatureType.COMPONENT_PROTOTYPE;
}
} else if (el instanceof FeaturePrototype) {
return getFeaturePrototypeType((FeaturePrototype) el);
} else if (el instanceof FeatureGroupPrototype) {
return FeatureType.FEATURE_GROUP_PROTOTYPE;
}
} else if (el instanceof PrototypeBinding) {
if (el instanceof ComponentPrototypeBinding) {
return FeatureType.COMPONENT_PROTOTYPE_BINDING;
} else if (el instanceof FeatureGroupPrototypeBinding) {
return FeatureType.FEATURE_GROUP_PROTOTYPE_BINDING;
} else // FeaturePrototypeBinding case.
{
return FeatureType.FEATURE_PROTOTYPE_BINDING;
}
} else if (el instanceof org.osate.aadl2.PropertyConstant) {
return FeatureType.PROPERTY_CONSTANT;
} else if (el instanceof org.osate.aadl2.Property) {
return FeatureType.PROPERTY_VALUE;
} else if (el instanceof ClassifierValue) {
return FeatureType.CLASSIFIER_VALUE;
} else if (el instanceof SubprogramGroup) {
return FeatureType.SUBPROGRAM_GROUP;
} else if (el instanceof SubprogramGroupAccess) {
switch(((SubprogramGroupAccess) el).getKind()) {
case PROVIDES:
return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
case REQUIRES:
return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
}
} else if (el instanceof ThreadGroup) {
return FeatureType.THREAD_GROUP;
} else if (el instanceof SystemSubcomponent) {
return FeatureType.SYSTEM_SUBCOMPONENT;
} else if (el instanceof SubprogramSubcomponent) {
return FeatureType.SUBPROGRAM_SUBCOMPONENT;
} else if (el instanceof SubprogramClassifier) {
return FeatureType.SUBPROGRAM_CLASSIFIER;
} else if (el instanceof DataSubcomponent) {
return FeatureType.DATA_SUBCOMPONENT;
} else if (el instanceof DataClassifier) {
return FeatureType.DATA_CLASSIFIER;
} else if (el instanceof ProcessorClassifier) {
return FeatureType.PROCESSOR_CLASSIFIER;
} else if (el instanceof ProcessClassifier) {
return FeatureType.PROCESS_CLASSIFIER;
}
String errorMsg = "getFeatureType : " + el.getClass().getSimpleName() + " is not supported yet at line " + Aadl2Utils.getLocationReference(el).getLine() + ".";
System.err.println(errorMsg);
throw new UnsupportedOperationException(errorMsg);
}
Aggregations