use of org.osate.ba.declarative.ArrayableIdentifier in project osate2 by osate.
the class AadlBaTypeChecker method subprogramParameterListCheck.
// This method checks the given parameter labels and matches them against the
// subprogram parameters. It resolves target/value expression semantic
// ambiguities. On error, reports error and returns false.
// Event if the subprogram call action doesn't have any parameter labels,
// the subprogram type may have and vice versa : subprogramParameterListCheck
// / is also design for these cases.
/**
* Document: AADL Behavior Annex draft
* Version : 0.94
* Type : Legality rule
* Section : D.6 Behavior Action Language
* Object : Check legality rule D.6.(L5)
* Keys : parameter list match signature subprogram call
*/
private boolean subprogramParameterListCheck(CommAction comAct, EList<ParameterLabel> callParams, Classifier subprogType) {
// Fetches sorted subprogram feature list.
List<Feature> tmp = Aadl2Utils.orderFeatures(subprogType);
List<Feature> subprogFeat = new ArrayList<Feature>(tmp.size());
for (Feature feat : tmp) {
if (feat instanceof DataAccess || feat instanceof Parameter) {
subprogFeat.add(feat);
}
}
// Preliminary checking : on error, reports error and exit early.
if (callParams.size() != subprogFeat.size()) {
String subprogramName = null;
if (comAct.getReference() != null) {
subprogramName = unparseReference(comAct.getReference());
} else {
subprogramName = unparseQualifiedNamedElement(comAct.getQualifiedName());
}
reportError(comAct, "Invalid number of argument(s) for the subprogram " + subprogramName);
return false;
}
boolean isconsistent = true;
boolean hasCheckingPassed = true;
Enum<?> currentDirRight;
ValueExpression valueExp;
ListIterator<ParameterLabel> it = callParams.listIterator();
Value v;
Target tar;
TypeHolder t1, t2;
ValueAndTypeHolder vth;
List<TypeHolder> typesFound = new ArrayList<TypeHolder>(callParams.size());
List<Enum<?>> dirRightsFound = new ArrayList<Enum<?>>(callParams.size());
List<TypeHolder> expectedTypes = new ArrayList<TypeHolder>(subprogFeat.size());
List<Enum<?>> expectedDirRight = new ArrayList<Enum<?>>(subprogFeat.size());
// driven by the subprogram signature.
for (Feature feat : subprogFeat) {
if (feat instanceof Parameter) {
Parameter param = (Parameter) feat;
currentDirRight = param.getDirection();
expectedDirRight.add(currentDirRight);
} else // DataAccess case.
{
DataAccess data = (DataAccess) feat;
currentDirRight = Aadl2Utils.getDataAccessRight(data);
expectedDirRight.add(currentDirRight);
}
valueExp = (ValueExpression) it.next();
Classifier klass = AadlBaUtils.getClassifier(feat, _baParentContainer);
// ValueExpression case.
if (currentDirRight == DirectionType.IN || currentDirRight == Aadl2Utils.DataAccessRight.read_only) {
vth = valueExpressionCheck(valueExp);
if (vth != null) {
try {
t1 = AadlBaUtils.getTypeHolder(klass);
} catch (DimensionException de) {
reportDimensionException(de);
return false;
}
t2 = vth.typeHolder;
expectedTypes.add(t1);
typesFound.add(t2);
dirRightsFound.add(DirectionType.IN);
if (!_dataChecker.conformsTo(t1, t2, true)) {
isconsistent = false;
}
} else // Value expression checking error case.
{
// Error reporting has already been done.
hasCheckingPassed = false;
}
} else if (currentDirRight != Aadl2Utils.DataAccessRight.unknown) {
v = AadlBaUtils.isOnlyOneValue(valueExp);
boolean isOnlyOneReference = false;
if (v instanceof Reference) {
Reference r = (Reference) v;
if (r.getIds().size() == 1) {
isOnlyOneReference = true;
}
}
if (// Target but not reference case.
v instanceof Target && isOnlyOneReference) {
TypeCheckRule stopOnThisRule = TypeCheckRule.DATA_ACCESS;
tar = targetCheck((Target) v, stopOnThisRule);
if (tar != null) {
try {
t1 = AadlBaUtils.getTypeHolder(klass);
t2 = AadlBaUtils.getTypeHolder(tar, _baParentContainer);
} catch (DimensionException de) {
reportDimensionException(de);
return false;
}
expectedTypes.add(t1);
typesFound.add(t2);
Enum<?> dirRightFound = AadlBaUtils.getDirectionType(tar);
if (dirRightFound == null) {
dirRightFound = AadlBaUtils.getDataAccessRight(tar);
}
dirRightsFound.add(dirRightFound);
if (!_dataChecker.conformsTo(t1, t2, true)) {
isconsistent = false;
} else {
// As checking passed and ambiguity between
// ValueExpression and Target has been resolved, it replaces
// the value expression by the target as parameter label.
it.set(tar);
}
} else // Target checking error case.
{
// Error reporting has already been done.
hasCheckingPassed = false;
}
} else // Value expression taken as a target -> warning arithmetic pointer operation.
{
// Due to target/value expression semantic ambiguity, the parsing
// phase may have introduced a semantic errors :
// If v == null :
// The parameter label has
// to be a value expression with a single value when the expected
// subprogram parameter is IN_OUT or OUT.
// If v is not instanceof Target but ValueExpression or Value
// like :
// _ IntegerConstant or ValueConstant
// _ PortFreshValue
// _ PortCountValue
// _ PortDequeueValue
// It resolves the type in order to format the warning message:
vth = valueExpressionCheck(valueExp);
if (vth != null) {
try {
t1 = AadlBaUtils.getTypeHolder(klass);
} catch (DimensionException de) {
reportDimensionException(de);
return false;
}
t2 = vth.typeHolder;
expectedTypes.add(t1);
typesFound.add(t2);
boolean inconsistentDir = false;
if (v instanceof Reference) {
Reference ref = (Reference) v;
ArrayableIdentifier refRootId = ref.getIds().get(0);
Enum<?> dirRightFound = null;
if (refRootId.getOsateRef() != null) {
dirRightFound = AadlBaUtils.getDirectionType(refRootId.getOsateRef());
}
if (dirRightFound == null && refRootId.getOsateRef() instanceof DataAccess) {
dirRightFound = Aadl2Utils.getDataAccessRight((DataAccess) refRootId.getOsateRef());
}
if (dirRightFound == DirectionType.IN || dirRightFound == Aadl2Utils.DataAccessRight.read_only) {
inconsistentDir = true;
}
} else {
inconsistentDir = true;
dirRightsFound.add(DirectionType.IN);
}
if (inconsistentDir) {
StringBuilder msg = new StringBuilder();
msg.append('\'');
msg.append(unparseNameElement(valueExp));
msg.append("\': is a read only value and it is used as a writable value");
// Reports a warning.
reportWarning(valueExp, msg.toString());
}
} else {
// Error reporting has already been done.
hasCheckingPassed = false;
}
}
} else {
reportError(valueExp, "can't fetch data access right. Set the default " + "right in memory_properties.aadl");
}
}
// Reports consistency error.
if (!isconsistent && hasCheckingPassed) {
String subprogramName = null;
if (comAct.getReference() != null) {
subprogramName = unparseReference(comAct.getReference());
} else {
subprogramName = unparseQualifiedNamedElement(comAct.getQualifiedName());
}
reportSubprogParamMatchingError(comAct, subprogramName, expectedTypes, expectedDirRight, typesFound, dirRightsFound);
}
return isconsistent && hasCheckingPassed;
}
use of org.osate.ba.declarative.ArrayableIdentifier in project osate2 by osate.
the class AadlBaNameResolver method communicationActionResolver.
private boolean communicationActionResolver(CommAction act) {
boolean result = true;
if (act.getTarget() != null) {
result &= targetResolver(act.getTarget());
}
if (act.getQualifiedName() != null) {
result &= qualifiedNamedElementResolver(act.getQualifiedName(), true);
}
if (act.getReference() != null) {
// Ambiguous cases :
// _ unqualified unique component classifier reference
// without implementation information provided, are parsed as reference
// (single name) without array index.
// _ unqualified unique component classifier reference with
// implementation information provided and a reference (two names)
// without array index.
Reference ref = act.getReference();
EList<ArrayableIdentifier> ids = ref.getIds();
boolean hasArrayIndex = false;
// names.
if (ids.size() > 2) {
result &= refResolver(ref);
} else {
for (ArrayableIdentifier id : ids) {
if (id.isSetArrayIndexes()) {
hasArrayIndex = true;
}
}
// unique component classifier reference can't have array index.
if (hasArrayIndex) {
result &= refResolver(ref);
} else {
// Resolves ambiguous case between unqualified unique component
// classifier reference and a reference with only one name.
ArrayableIdentifier idComponent = ids.get(0);
StringBuilder subprogramName = new StringBuilder();
subprogramName.append(idComponent.getId());
if (ids.size() == 2) {
ArrayableIdentifier idImplementation = ids.get(1);
subprogramName.append('.');
subprogramName.append(idImplementation.getId());
}
QualifiedNamedElement qne = DeclarativeFactory.eINSTANCE.createQualifiedNamedElement();
// Clone the identifier as object reference in the most of the AADLBA
// Front End emf meta model classes are unique (the containment
// attribute set to true).
Identifier idClone = DeclarativeFactory.eINSTANCE.createIdentifier();
idClone.setLocationReference(idComponent.getLocationReference());
idClone.setId(subprogramName.toString());
qne.setBaName(idClone);
qne.setBaNamespace(null);
qne.setLocationReference(idComponent.getLocationReference());
if (qualifiedNamedElementResolver(qne, false)) {
act.setReference(null);
act.setQualifiedName(qne);
act.setLocationReference(qne.getLocationReference());
result &= true;
} else {
result &= refResolver(ref);
}
}
}
}
if (act.isSetParameters()) {
result &= subprogramParameterListResolver(act.getParameters());
}
return result;
}
use of org.osate.ba.declarative.ArrayableIdentifier 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.ba.declarative.ArrayableIdentifier in project osate2 by osate.
the class AadlBaTypeChecker method refResolver.
// Checks group rules by default.
// Special attention is provided for Value or Target that are not
// data component references (ex: PortHolder): if stopOnThisRule is found
// and extra information exists (ex: port.port which syntactically correct but
// semantically wrong), it will report extraneous information error.
// If given port is not null, elementHolderResolver will try to set it
// (optimize reinstanciation when using design pattern decoration, for
// PortActions and PortValues).
// Also, IterativeVariable and BehaviorVariable instances can't have any
// group information. It will report extraneous information error if
// groups are provided.
// This method can't detect if there is not enought information (currently
// just for required_data_access_name.provided_subprogram_access_name case).
private List<ElementHolder> refResolver(Reference ref, ActualPortHolder port, TypeCheckRule stopOnThisRule, TypeCheckRule... checkRules) {
List<ElementHolder> result = new ArrayList<ElementHolder>(ref.getIds().size());
Enum<?> currentResult = null;
ElementHolder currentElementholder = null;
int currentIndexRule = 0;
TypeCheckRule currentRule = checkRules[currentIndexRule];
TypeCheckRule lastRule = checkRules[checkRules.length - 1];
boolean hasToContinue = true;
ArrayList<GroupHolder> grpl = new ArrayList<GroupHolder>(ref.getIds().size());
ListIterator<ArrayableIdentifier> it = ref.getIds().listIterator();
while (it.hasNext()) {
ArrayableIdentifier id = it.next();
currentResult = typeCheck(id, id.getId(), TypeCheckRule.GROUPS, false);
// The current id represents a group, so store it in the groups stack.
if (currentResult != null) {
currentElementholder = elementHolderResolver(id, currentResult, port);
grpl.add((GroupHolder) currentElementholder);
} else // Checks given rules: if ref.getIds().size > rules.length then
// use the last given rule for the extra ids.
{
currentResult = typeCheck(id, id.getId(), currentRule, true);
if (currentResult != null) {
currentElementholder = elementHolderResolver(id, currentResult, port);
result.add(currentElementholder);
if (currentElementholder instanceof GroupableElement) {
if (false == grpl.isEmpty()) {
GroupableElement ge = (GroupableElement) currentElementholder;
// Flush GroupHolder List.
if (false == grpl.isEmpty()) {
ge.getGroupHolders().addAll(grpl);
grpl.clear();
}
}
} else if (false == grpl.isEmpty()) {
// Reports error of a not GroupableHolder that have group information.
String msg = id.getId() + " can't have group information.";
reportError(id, msg);
return null;
}
// Tests if a type that stop the checking is found.
hasToContinue = stopOnThisRule.testTypeCheckRule(currentResult) == null;
if (it.hasNext()) {
currentIndexRule++;
// So report error.
if (hasToContinue == false) {
// To much information.
String msg = id.getId() + " can't have any more tokens.";
reportError(id, msg);
return null;
} else // Stop type is not reached or is null that means there is
// not id number limit.
{
// If the number of ids is greater than the number of given
// rules: use the last rule for the extra ids. Only for data
// component reference.
currentRule = (currentIndexRule < checkRules.length) ? checkRules[currentIndexRule] : lastRule;
}
}
} else {
// Error reporting has already been done.
return null;
}
}
// Checks array indexes.
if (id.isSetArrayIndexes()) {
if (currentElementholder instanceof IndexableElement) {
IndexableElement currentIndexableElement = (IndexableElement) currentElementholder;
boolean isConsistent = true;
List<IntegerValue> resolvedValues = new ArrayList<IntegerValue>(id.getArrayIndexes().size());
for (IntegerValue iv : id.getArrayIndexes()) {
// Reports any error.
IntegerValue resolvedValue = integerValueCheck(iv);
if (resolvedValue != null) {
resolvedValues.add(resolvedValue);
} else {
isConsistent = false;
}
}
// and currentIndexableElement's one.
if (isConsistent) {
currentIndexableElement.getArrayIndexes().addAll(resolvedValues);
}
} else {
// Not an arrayable element.
String msg = currentElementholder.getElement().getName() + " can't have array index.";
reportError(currentElementholder, msg);
return null;
}
}
}
// End of for.
if (result.isEmpty()) {
String expectedTypes = currentRule.getExpectedTypes(STRING_TYPE_SEPARATOR);
String errMsg = "Wrong type in " + stopOnThisRule.getLiteral() + "; expected types are: " + expectedTypes;
this.reportError(ref, errMsg);
return null;
}
return result;
}
use of org.osate.ba.declarative.ArrayableIdentifier in project osate2 by osate.
the class AadlBaNameResolver method refResolver.
// Resolves Reference objects (arrayable identifiers)
// within parent component's features ones and ba's variables ones and
// for/forall's iterative variable scope handler.
private boolean refResolver(Classifier parentContainer, Reference ref) {
boolean result = true;
boolean currentIdResult = false;
ListIterator<ArrayableIdentifier> it = ref.getIds().listIterator();
// Checks ArrayableIdentifier objects.
while (it.hasNext()) {
ArrayableIdentifier id = it.next();
// Can't resolve within a null parent classifier.
if (parentContainer == null) {
result = false;
reportNameError(id, id.getId());
break;
}
if (parentContainer == _baParentContainer) {
currentIdResult = identifierBaResolver(id, false);
}
if (!currentIdResult) {
currentIdResult = identifierComponentResolver(id, parentContainer, true);
}
if (id.isSetArrayIndexes()) {
// Checks array indexes names.
for (IntegerValue index : id.getArrayIndexes()) {
// Recursive call.
result &= integerValueResolver(index);
}
}
// If the current id is found, fetch the container for the next id.
if (currentIdResult && it.hasNext()) {
Element el = AadlBaTypeChecker.getBindedElement(id);
// not been type checked already.
if (el instanceof BehaviorVariable) {
QualifiedNamedElement qne = (QualifiedNamedElement) ((BehaviorVariable) el).getDataClassifier();
parentContainer = (Classifier) qne.getOsateRef();
} else if (el instanceof IterativeVariable) {
IterativeVariable itv = (IterativeVariable) el;
QualifiedNamedElement qne = (QualifiedNamedElement) itv.getDataClassifier();
parentContainer = (Classifier) qne.getOsateRef();
} else {
parentContainer = AadlBaUtils.getClassifier(el, parentContainer);
}
}
// Add the current id result to the global result.
result &= currentIdResult;
// Reset.
currentIdResult = false;
// Don't continue if the current id is not found.
if (result == false) {
break;
}
}
// Binds with the last id reference.
ArrayableIdentifier lastId = ref.getIds().get((ref.getIds().size() - 1));
ref.setOsateRef(lastId.getOsateRef());
ref.setBaRef(lastId.getBaRef());
return result;
}
Aggregations