Search in sources :

Example 41 with Feature

use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.

the class AadlBaNameResolver method featureNameUniquenessCheck.

// Just the opposite of featureResolver.
private boolean featureNameUniquenessCheck(IterativeVariable itv) {
    String nameToFind = itv.getName();
    Feature f = Aadl2Visitors.findFeatureInComponent(_baParentContainer, nameToFind);
    if (f == null) {
        return true;
    } else {
        // Report error.
        _errManager.error(itv, "duplicate local variable for " + itv.getName());
        return false;
    }
}
Also used : Feature(org.osate.aadl2.Feature) ClassifierFeature(org.osate.aadl2.ClassifierFeature)

Example 42 with Feature

use of com.google.cloud.vision.v1p4beta1.Feature 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;
}
Also used : LocationReference(org.osate.aadl2.parsesupport.LocationReference) Reference(org.osate.ba.declarative.Reference) DeclarativePropertyReference(org.osate.ba.declarative.DeclarativePropertyReference) ArrayList(java.util.ArrayList) Classifier(org.osate.aadl2.Classifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) Feature(org.osate.aadl2.Feature) ArrayableIdentifier(org.osate.ba.declarative.ArrayableIdentifier) DataAccess(org.osate.aadl2.DataAccess) NamedValue(org.osate.ba.declarative.NamedValue) NumberValue(org.osate.aadl2.NumberValue) ClassifierValue(org.osate.aadl2.ClassifierValue) Parameter(org.osate.aadl2.Parameter) DimensionException(org.osate.ba.utils.DimensionException)

Example 43 with Feature

use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.

the class AadlBaUtils method getClassifier.

/**
 * Returns the given Element object's classifier.
 * If the Element object is a prototype, it will try to resolve it as
 * follow: returns the data prototype binded classifier at first withing the
 * element's parent container otherwise the constraining classifier.
 * It returns {@code null} if the prototype is not defined.
 * <BR><BR>
 * This method support instances of:<BR>
 * <BR>_Feature (port, data access, subprogram access, parameter, etc.)
 * <BR>_Subcomponent (data subcomponent, subprogram subcomponent, etc.)
 * <BR>_BehaviorVariable
 * <BR>_IterativeVariable (for/forall's iterative variable)
 * <BR>_Prototype (all excepted FeatureGroupPrototype)
 * <BR>_PrototypeBinding (all excepted FeatureGroupPrototypeBinding)
 * <BR>_ClassifierValue (struct or union data subcomponent)
 * <BR><BR>
 * If the given Element object is not one of those types, an
 * UnsupportedOperationException is thrown.
 *
 * @param el the given Element object
 * @param parentContainer the element's parent component.
 * @return the given element's classifier or {@code null} if the prototype is
 * not defined
 * @exception UnsupportedOperationException for unsupported element
 * object types.
 */
public static Classifier getClassifier(Element el, Classifier parentContainer) {
    Classifier result = null;
    if (el instanceof Feature) {
        Feature f = (Feature) el;
        if (el instanceof FeatureGroup) {
            org.osate.aadl2.FeatureType ft = ((FeatureGroup) el).getFeatureType();
            if (ft != null) {
                if (ft instanceof FeatureGroupType) {
                    result = (FeatureGroupType) ft;
                } else // FeatureGroupPrototype case
                {
                    result = getClassifier((FeatureGroupPrototype) ft, parentContainer);
                }
            }
        } else {
            // Feature case.
            result = f.getClassifier();
            // Feature without classifier returns null.
            if (result == null && f.getPrototype() != null) {
                result = prototypeResolver(f.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof Subcomponent) {
        Subcomponent sub = (Subcomponent) el;
        if (el instanceof SubprogramGroupSubcomponent) {
            result = ((SubprogramGroupSubcomponent) el).getClassifier();
        } else {
            // Subcomponent case.
            result = sub.getClassifier();
            // Subcomponent without classifier returns null.
            if (result == null && sub.getPrototype() != null) {
                result = prototypeResolver(sub.getPrototype(), parentContainer);
            }
        }
    } else if (el instanceof BehaviorVariable) {
        // Local variable case (BehaviorVariable).
        BehaviorVariable bv = (BehaviorVariable) el;
        result = bv.getDataClassifier();
    } else if (el instanceof IterativeVariable) {
        // Iterative variable case.
        result = ((IterativeVariable) el).getDataClassifier();
    } else if (el instanceof Prototype) {
        result = prototypeResolver((Prototype) el, parentContainer);
    } else if (el instanceof PrototypeBinding) {
        // Prototype binding case.
        result = prototypeBindingResolver((PrototypeBinding) el);
    } else if (el instanceof ClassifierValue) {
        // struct or union member case (ClassifierValue).
        result = ((ClassifierValue) el).getClassifier();
    } else if (el instanceof StructUnionElement) {
        return ((StructUnionElement) el).getDataClassifier();
    } else {
        // Reports error.
        String errorMsg = "getClassifier : " + el.getClass().getSimpleName() + " is not supported yet.";
        System.err.println(errorMsg);
        throw new UnsupportedOperationException(errorMsg);
    }
    return result;
}
Also used : IterativeVariable(org.osate.ba.aadlba.IterativeVariable) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) BehaviorVariable(org.osate.ba.aadlba.BehaviorVariable) FeatureGroupType(org.osate.aadl2.FeatureGroupType) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) AadlString(org.osate.aadl2.AadlString) StructUnionElement(org.osate.ba.aadlba.StructUnionElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding)

Example 44 with Feature

use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.

the class AadlBaUtils method prototypeBindingResolverForDataComponentReference.

/**
 * Returns the DataClassifier object associated to prototype binding in a DataComponentReference
 *
 * @param r the DataComponentRefenrence object from which the binding will be resolved
 * @param dp the DataPrototpye object that enables to identify the targeted prototype binding
 * @param parentContainer the object that contains the element binded to the
 * given DataComponentRefenrence
 * @return the DataClassifier object
 */
private static DataClassifier prototypeBindingResolverForDataComponentReference(DataComponentReference r, DataPrototype dp, NamedElement parentContainer) {
    if (r.getData().size() > 1) {
        DataHolder h = r.getData().get(r.getData().size() - 2);
        NamedElement parent = h.getElement();
        if (parent instanceof Classifier) {
            Classifier c = (Classifier) parent;
            return getDataClassifier(c.getOwnedPrototypeBindings(), dp);
        }
        if (parent instanceof Subcomponent) {
            Subcomponent s = (Subcomponent) parent;
            return getDataClassifier(s.getOwnedPrototypeBindings(), dp);
        } else if (parent instanceof DataAccess) {
            DataAccess da = (DataAccess) parent;
            DataSubcomponentType parentDst = da.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataAccess && f.getName().equals(parent.getName())) {
                            DataAccess containerDa = (DataAccess) f;
                            DataSubcomponentType containerDst = containerDa.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        } else if (parent instanceof DataPort) {
            DataPort dataport = (DataPort) parent;
            DataSubcomponentType parentDst = dataport.getDataFeatureClassifier();
            Classifier c = (Classifier) parentDst;
            DataClassifier matchedPrototype = getDataClassifier(c.getOwnedPrototypeBindings(), dp);
            if (matchedPrototype == null) {
                if (parentContainer instanceof ComponentType) {
                    ComponentType ct = (ComponentType) parentContainer;
                    for (Feature f : ct.getOwnedFeatures()) {
                        if (f instanceof DataPort && f.getName().equals(parent.getName())) {
                            DataPort containerDp = (DataPort) f;
                            DataSubcomponentType containerDst = containerDp.getDataFeatureClassifier();
                            Classifier c2 = (Classifier) containerDst;
                            return getDataClassifier(c2.getOwnedPrototypeBindings(), dp);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) DataSubcomponentType(org.osate.aadl2.DataSubcomponentType) ComponentType(org.osate.aadl2.ComponentType) DataHolder(org.osate.ba.aadlba.DataHolder) Subcomponent(org.osate.aadl2.Subcomponent) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) SubprogramGroupSubcomponent(org.osate.aadl2.SubprogramGroupSubcomponent) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) ProcessClassifier(org.osate.aadl2.ProcessClassifier) DataClassifier(org.osate.aadl2.DataClassifier) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataClassifier(org.osate.aadl2.DataClassifier) BehaviorNamedElement(org.osate.ba.aadlba.BehaviorNamedElement) NamedElement(org.osate.aadl2.NamedElement) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature) DirectedFeature(org.osate.aadl2.DirectedFeature) DataAccess(org.osate.aadl2.DataAccess)

Example 45 with Feature

use of com.google.cloud.vision.v1p4beta1.Feature in project osate2 by osate.

the class Aadl2Utils method orderFeatures.

/**
 * Returns the sorted (see FeaturePositionComparator) list of features (included
 * inherited features) owned by the given Classifier object.
 *
 * @param cpt the given Classifier object
 * @param inheritedBindings inherited prototype bindings
 * @return the sorted list of features owned by the given Component object
 */
public static List<Feature> orderFeatures(Classifier cpt, List<PrototypeBinding> inheritedBindings) {
    // List<PrototypeBinding> bindings = cpt.getOwnedPrototypeBindings();
    List<PrototypeBinding> bindings = new ArrayList<PrototypeBinding>();
    bindings.addAll(cpt.getOwnedPrototypeBindings());
    bindings.addAll(inheritedBindings);
    List<Feature> res = new ArrayList<Feature>();
    for (Feature f : cpt.getAllFeatures()) {
        res.add(getBindedFeature(bindings, f));
    }
    // res.addAll(cpt.getAllFeatures()) ;
    FeaturePositionComparator comparator = new FeaturePositionComparator();
    Collections.sort(res, comparator);
    return res;
}
Also used : ArrayList(java.util.ArrayList) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) PrototypeBinding(org.osate.aadl2.PrototypeBinding) Feature(org.osate.aadl2.Feature) AbstractFeature(org.osate.aadl2.AbstractFeature)

Aggregations

Feature (org.osate.aadl2.Feature)82 ArrayList (java.util.ArrayList)78 Feature (com.google.cloud.vision.v1.Feature)72 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)69 Image (com.google.cloud.vision.v1.Image)69 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)66 ImageAnnotatorClient (com.google.cloud.vision.v1.ImageAnnotatorClient)66 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)63 ByteString (com.google.protobuf.ByteString)47 ImageSource (com.google.cloud.vision.v1.ImageSource)38 FileInputStream (java.io.FileInputStream)30 Subcomponent (org.osate.aadl2.Subcomponent)29 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)27 Classifier (org.osate.aadl2.Classifier)27 WebImage (com.google.cloud.vision.v1.WebDetection.WebImage)26 ComponentClassifier (org.osate.aadl2.ComponentClassifier)22 NamedElement (org.osate.aadl2.NamedElement)22 FeatureGroup (org.osate.aadl2.FeatureGroup)18 FeatureInstance (org.osate.aadl2.instance.FeatureInstance)17 FeatureGroupType (org.osate.aadl2.FeatureGroupType)16