use of org.osate.aadl2.NamedValue in project osate2 by osate.
the class Aadl2Utils method getAccessRight.
/**
* Returns the access right of the given NamedElement object.<BR>
* <BR>
*
* Returns the local "Access_Right" property value, if it is set. Otherwise,
* returns the default access right value found in Memory_Properties (pre
* declared property set). If the default access right is not found, it
* returns "unknown".
*
* @param ne the given NamedElement object
* @return local access right or default access right or "unknown"
*/
public static String getAccessRight(NamedElement ne) {
String result = PropertyUtils.getEnumValue(ne, "Access_Right");
if (result == null) {
if (DEFAULT_ACCESS_RIGHT == null) {
Property prop = GetProperties.lookupPropertyDefinition(ne, "Memory_Properties", "Access_Right");
if (prop != null) {
NamedValue nv = (NamedValue) prop.getDefaultValue();
result = ((EnumerationLiteral) nv.getNamedValue()).getName();
DEFAULT_ACCESS_RIGHT = result;
} else {
return "unknown";
}
} else {
return DEFAULT_ACCESS_RIGHT;
}
}
return result;
}
use of org.osate.aadl2.NamedValue in project osate2 by osate.
the class PropertyUtils method getStringListValue.
/**
* Extract String list value from a specified property. May return null.
*
* @param i
* component instance.
* @param propertyName
* property name.
* @return property value.
*/
public static List<String> getStringListValue(NamedElement i, String propertyName) {
List<String> res = new ArrayList<String>();
PropertyAssociation pa = findPropertyAssociation(propertyName, i);
if (pa != null) {
Property p = pa.getProperty();
if (p.getName().equalsIgnoreCase(propertyName)) {
List<ModalPropertyValue> values = pa.getOwnedValues();
if (values.size() == 1) {
ModalPropertyValue v = values.get(0);
PropertyExpression expr = v.getOwnedValue();
if (expr instanceof ListValue) {
ListValue lv = (ListValue) expr;
for (PropertyExpression pe : lv.getOwnedListElements()) {
if (pe instanceof StringLiteral) {
StringLiteral sl = (StringLiteral) pe;
res.add(sl.getValue());
} else if (pe instanceof NamedValue) {
NamedValue nv = (NamedValue) pe;
if (nv.getNamedValue() instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) nv.getNamedValue();
res.add(el.getName());
}
}
}
if (!res.isEmpty()) {
return res;
}
}
}
}
}
return null;
}
use of org.osate.aadl2.NamedValue in project osate2 by osate.
the class AadlBaLegalityRulesChecker method D_4_L1_Check.
/**
* Document: AADL Behavior Annex draft
* Version : 0.94
* Type : Legality rule and Semantic rule
* Section : D.4 Thread Dispatch Behavior Specification
* Object : Check legality rule D.4.(L1) and semantic rule D.4.(5)
* Keys : dispatch relative timeout condition catch timed thread complete
* state period property
*/
public boolean D_4_L1_Check(DispatchRelativeTimeout tc, DeclarativeBehaviorTransition bt) {
List<Identifier> sourceState = bt.getSrcStates();
if (sourceState.size() == 1) {
BehaviorState bs = (BehaviorState) (sourceState.get(0)).getBaRef();
if (false == _alreadyFoundDispatchRelativeTimeoutTransition.containsKey(bs) && bs.isComplete()) {
// If the ba's parent container is not a Thread, the return value
// list will be empty.
EList<org.osate.aadl2.PropertyExpression> vl;
vl = PropertyUtils.findPropertyExpression(_baParentContainer, ThreadProperties.DISPATCH_PROTOCOL);
if (vl.size() > 0) {
org.osate.aadl2.PropertyExpression value = vl.get(vl.size() - 1);
if (value instanceof NamedValue && ((NamedValue) value).getNamedValue() instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) ((NamedValue) value).getNamedValue();
String literal = el.getName();
if (literal.equalsIgnoreCase(DispatchTriggerProperties.TIMED)) {
boolean hasPeriod = false;
Long period = PropertyUtils.getIntValue(_baParentContainer, TimingProperties.PERIOD);
hasPeriod = period != null;
if (hasPeriod) {
_alreadyFoundDispatchRelativeTimeoutTransition.put(bs, bt);
return true;
} else // Error case: period property must be declared in the
// ba's parent container.
{
reportLegalityError(tc, "The dispatch relative timeout" + " and catch statement must declared in timed " + " thread with a period property properly set: " + " Behavior Annex D.4.(5) semantic rule failed");
// Early exit to skip the next error reporting.
return false;
}
}
}
}
// Error case : it must only be declared for timed thread.
this.reportLegalityError(tc, "The dispatch relative timeout and" + " catch statement must only be declared for timed thread: " + "Behavior Annex D.4.(L1) legality rule failed");
} else // Error case : It must be declared in an outgoing transition of
// a complete state.
{
if (false == _alreadyReportedErroneousTransition.contains(bt)) {
this.reportLegalityError(tc, "The dispatch relative timeout and " + "catch statement must be declared in an outgoing transition " + "of a complete state: Behavior Annex" + " D.4.(L1) legality rule failed");
_alreadyReportedErroneousTransition.add(bt);
}
}
} else // Error case : It must be declared in only one transition of the source state.
{
// If transition source states list is > 1, report errors for the
// furthers timeout catch.
this.reportLegalityError(tc, "The dispatch relative timeout and catch" + " statement must be declared in only one transition: " + "Behavior Annex D.4.(L1) legality rule failed");
}
return false;
}
use of org.osate.aadl2.NamedValue in project osate2 by osate.
the class AadlBaLegalityRulesChecker method D_4_L2_Check.
/**
* Document: AADL Behavior Annex draft
* Version : 0.94
* Type : Legality rule
* Section : D.4 Thread Dispatch Behavior Specification
* Object : Check legality rule D.4.(L2)
* Keys : dispatch completion relative timeout condition catch complete
* state
*/
public Boolean D_4_L2_Check(CompletionRelativeTimeout crtcac, DeclarativeBehaviorTransition bt) {
List<Identifier> sourceState = bt.getSrcStates();
if (!_alreadyFoundCompletionRelativeTimeoutConditionCatchTransition.containsKey(sourceState) && sourceState.size() == 1) {
BehaviorState bs = (BehaviorState) (sourceState.get(0)).getBaRef();
// Positive case.
if (bs.isComplete()) {
_alreadyFoundCompletionRelativeTimeoutConditionCatchTransition.put(bs, bt);
EList<org.osate.aadl2.PropertyExpression> vl;
vl = PropertyUtils.findPropertyExpression(_baParentContainer, ThreadProperties.DISPATCH_PROTOCOL);
if (vl.size() > 0) {
org.osate.aadl2.PropertyExpression value = vl.get(vl.size() - 1);
if (value instanceof NamedValue && ((NamedValue) value).getNamedValue() instanceof EnumerationLiteral) {
EnumerationLiteral el = (EnumerationLiteral) ((NamedValue) value).getNamedValue();
String literal = el.getName();
if (literal.equalsIgnoreCase(DispatchTriggerProperties.TIMED)) {
boolean hasPeriod = false;
Long period = PropertyUtils.getIntValue(_baParentContainer, TimingProperties.PERIOD);
hasPeriod = period != null;
Long timeoutConstantValue = null;
IntegerValue iv = crtcac.getIntegerValue();
if (iv instanceof IntegerLiteral) {
timeoutConstantValue = ((IntegerLiteral) iv).getValue();
}
boolean timeoutIsConstant = timeoutConstantValue != null;
// otherwise it is inconsistent.
if (hasPeriod && timeoutIsConstant && period < timeoutConstantValue) {
this.reportLegalityError(crtcac, "The completion relative timeout" + " condition and catch statement must have a value greater or" + " equal to the Period of the thread it is defined in (otherwise)" + " timeout condition can never occur");
}
}
}
}
return true;
} else // Error case : it must be declared in an outgoing transition of
// a complete state.
{
this.reportLegalityError(crtcac, "The completion relative timeout" + " condition and catch statement must be declared in an " + "outgoing transition of a complete state: Behavior Annex" + " D.4.(L2) legality rule failed");
}
} else // Error case : it must be declared in at most one transition.
{
// furthers completion timeout catch.
if (false == _alreadyReportedErroneousTransition.contains(bt)) {
this.reportLegalityError(crtcac, "The completion relative timeout " + "condition and catch statement must be declared in only one " + "transition: Behavior Annex D.4.(L2) legality rule failed");
_alreadyReportedErroneousTransition.add(bt);
}
}
return false;
}
use of org.osate.aadl2.NamedValue in project osate2 by osate.
the class AadlBaTypeChecker method valueVariableCheck.
// This method checks the given object and returns a value variable
// resolved from semantic ambiguities and its data representation. On error,
// reports error and returns null.
private ValueAndTypeHolder valueVariableCheck(ValueVariable v) {
List<ElementHolder> ehl = null;
ValueVariable tmpResult = null;
ActualPortHolder port;
TypeCheckRule stopRule;
TypeCheckRule[] checkRules;
if (v instanceof Reference) {
port = null;
stopRule = TypeCheckRule.VV_STOP_RULE;
checkRules = new TypeCheckRule[] { TypeCheckRule.VV_COMPONENT_REFERENCE_FIRST_NAME, TypeCheckRule.DATA_COMPONENT_REFERENCE_OTHER_NAMES };
} else // NamedValue case.
{
NamedValue nv = (NamedValue) v;
v = nv.getReference();
if (nv.isCount()) {
port = _fact.createPortCountValue();
stopRule = TypeCheckRule.PORT_COUNT_VALUE;
} else if (nv.isDequeue()) {
port = _fact.createPortDequeueValue();
stopRule = TypeCheckRule.PORT_DEQUEUE_VALUE;
} else {
port = _fact.createPortFreshValue();
stopRule = TypeCheckRule.PORT_FRESH_VALUE;
}
port.setLocationReference(v.getLocationReference());
checkRules = new TypeCheckRule[] { stopRule };
}
ehl = refResolver((Reference) v, port, stopRule, checkRules);
if (ehl != null) {
tmpResult = referenceToValueVariable(ehl);
if (tmpResult instanceof PortFreshValue) {
PortFreshValue pfv = (PortFreshValue) tmpResult;
AadlBaVisitors.putFreshPort(_ba, pfv.getPort());
}
return this.getValueAndTypeHolder(tmpResult, v);
} else {
return null;
}
}
Aggregations