Beispiel #1
0
    def processInheritances(self, inheritances):
        # process each inheritance, stores a dict with each subclass as the key
        # and a list of tuples (superclass, priority) as the value. The priority
        # tells us which class to inherit from first for multiple inheritance. Gives
        # a WARNING with a given inheritance order if two priorities are the same

        for i in inheritances :
            self.super_classes.append((i.get("class",""),i.get("priority",1)))

        try:
            self.super_classes.sort(lambda a, b: cmp(b[1], a[1])) # sort from high priority to low priority
        except TypeError:
            self.super_classes = sorted(self.super_classes, key=lambda x: x[1], reverse = True)

        priorityChecker = {}
        for super_class, priority in self.super_classes:
            if priority in priorityChecker:
                checkIt = priorityChecker[priority]
            else:
                checkIt = []
            if super_class not in checkIt:
                checkIt.append(super_class)
            priorityChecker[priority] = checkIt

        for priority, checkIt in list(priorityChecker.items()):
            if len(checkIt) > 1:
                Logger.showWarning("Class <" + self.name + "> inherits from classes <" + ", ".join(checkIt) + "> with same priority <" + str(priority) + ">. Document inheritance order is used.")

        self.super_classes = [entry[0] for entry in self.super_classes]
Beispiel #2
0
    def visit_Class(self, c):
        # replace super class names by super class objects
        for s in c.super_classes:
            super_class = None
            for clas in c.class_diagram.classes:
                if clas.name == s:
                    super_class = clas
            if super_class == None:
                Logger.showWarning("Class <" + c.name +
                                   "> has undefined super class <" + s + ">.")
            else:
                c.super_class_objs[s] = super_class

        # calculate list of abstract methods
        c.abstract_method_names = getClassAbstractMethodNames(c)

        # check if <super> tags exist for all inherited classes
        for name, obj in list(c.super_class_objs.items()):
            if obj:
                if name not in c.constructors[0].super_class_parameters:
                    num_params = len(obj.constructors[0].parameters)
                    if num_params > 0:
                        raise CompilerException(
                            "Class <" + c.name + "> inherits <" + name +
                            "> and <" + name + ">'s constructor has " +
                            str(num_params) +
                            " parameter(s), but there's no <super> entry for that class in <"
                            + c.name + ">'s constructor.")
Beispiel #3
0
 def __init__(self, xml_element):
     self.event = xml_element.get("event","").strip()
     scope_string = xml_element.get("scope","").strip().lower()
     self.target = xml_element.get("target","").strip()
     self.port = xml_element.get("port","").strip()
     
     if scope_string == "local" :
         self.scope = self.LOCAL_SCOPE
     elif scope_string == "broad" :
         self.scope = self.BROAD_SCOPE
     elif scope_string == "output" :
         self.scope = self.OUTPUT_SCOPE
     elif scope_string == "narrow" :
         self.scope = self.NARROW_SCOPE
     elif scope_string == "cd" :
         self.scope = self.CD_SCOPE
     elif scope_string == "" :
         #Calculate scope depending on present attributes
         if self.target and self.port :
             raise CompilerException("Both target and port attribute detected without a scope defined.")
         elif self.port :
             self.scope = self.OUTPUT_SCOPE
         elif self.target :
             self.scope = self.NARROW_SCOPE
         else :
             self.scope = self.LOCAL_SCOPE  
         
     else :
         raise CompilerException("Illegal scope attribute; needs to be one of the following : local, broad, narrow, output, cd or nothing.");  
             
     if self.scope == self.LOCAL_SCOPE or self.scope == self.BROAD_SCOPE or self.scope == self.CD_SCOPE:
         if self.target :
             Logger.showWarning("Raise event target detected, not matching with scope. Ignored.")
             self.target = ""
         if self.port :
             Logger.showWarning("Raise event port detected, not matching with scope. Ignored.")
             self.port = ""
     if self.scope == self.NARROW_SCOPE and self.port :
         Logger.showWarning("Raise event port detected, not matching with scope. Ignored.")
         self.port = ""
     if self.scope == self.OUTPUT_SCOPE and self.target :
         Logger.showWarning("Raise event target detected, not matching with scope. Ignored.")
         self.target = ""
             
     self.params = []
     parameters = xml_element.findall('parameter')    
     for p in parameters :
         value = p.get("expr","")
         if not value :
             raise CompilerException("Parameter without value detected.")
         self.params.append(Expression(value))
Beispiel #4
0
    def __init__(self, class_obj, statechart_xml):
        """ Gives the module information on the statechart by listing its basic, orthogonal,
            composite and history states as well as mapping triggers to names making the
            appropriate conversion from AFTER() triggers to event names
        """
        
        self.class_obj = class_obj
        self.root = StateChartNode(self, statechart_xml); #creates the whole statechart structure recursively

        self.states = []
        self.basics = []
        self.composites = []
        self.histories = []
        self.nr_of_after_transitions = 0

        def getSemanticOption(name, allowed_values, default_value):
            result = statechart_xml.get(name, default_value)
            if result not in allowed_values:
                raise CompilerException("Illegal value for semantic option " + name + ": '" + result + "'. Allowed values are ['" + "', '".join(allowed_values) + "'], default value is '" + default_value + "'.")
            return result

        self.big_step_maximality = getSemanticOption("big_step_maximality", ["take_one", "take_many"], "take_many")
        self.internal_event_lifeline = getSemanticOption("internal_event_lifeline", ["next_small_step", "next_combo_step", "queue"], "queue")
        self.input_event_lifeline = getSemanticOption("input_event_lifeline", ["first_small_step", "first_combo_step", "whole"], "first_combo_step")
        self.priority = getSemanticOption("priority", ["source_parent", "source_child"], "source_parent")
        self.concurrency = getSemanticOption("concurrency", ["single", "many"], "single")

        if self.internal_event_lifeline == "next_combo_step":
            if self.big_step_maximality == "take_one":
                Logger.showWarning("Using 'Next Combo Step' internal event lifeline semantics and 'Take One' big step maximality semantics simultaneously doesn't make sense.")

        self.extractFromHierarchy(self.root) # recursively extracts the basics, composites, histories and nr_of_after_transitions
            
        # Calculate the history that needs to be taken care of.
        self.shallow_history_parents = []
        self.deep_history_parents = []
        self.combined_history_parents = [] #All nodes that need state saved on leaving
        for node in self.histories:
            self.calculateHistory(node.parent, node.is_history_deep)
 def generic_visit(self, node):
     Logger.showWarning(
         "GenericGenerator has no visit method for node of type '" +
         str(type(node)) + "'.")