Ejemplo n.º 1
0
def parse_typename(tname, source):
    if len(tname) == 0:
        raise utils.PtpException("Missing type", source)
    try:
        return typename.parseString(tname, parseAll=True)
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)
Ejemplo n.º 2
0
def parse_edge_expression(string, source):
    if len(string.strip()) == 0:
        raise utils.PtpException("Missing expression", source)

    try:
        inscriptions = edge_expr.parseString(string, parseAll=True)
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)
Ejemplo n.º 3
0
def load_project(element, target_envs, build_target="build", load_nets=True):
    target_env = utils.xml_str(element, "target_env")
    if target_env not in target_envs:
        raise utils.PtpException("Unknown target environment")

    description = element.find("description").text
    name = utils.xml_str(element, "name")
    root_directory = utils.xml_str(element, "root-directory")

    p = Project(name,
                root_directory,
                target_envs[target_env],
                description)
    p.build_target = build_target

    p.library_rpc = utils.xml_bool(element, "library-rpc", False)
    p.library_octave = utils.xml_bool(element, "library-octave", False)
    p.tracing = utils.xml_bool(element, "tracing", False)

    load_configuration(element.find("configuration"), p)

    if not load_nets:
        return p

    nets = [ (e, load_net(e, p)) for e in element.findall("net") ]
    p.nets = [ net for e, net in nets ]
    for e, net in nets:
        load_net_content(e, p, net)
    return p
Ejemplo n.º 4
0
def write_parameters(builder):
    for p in builder.project.get_parameters():
        policy = "ca::PARAMETER_" + p.get_policy().upper()
        if p.get_policy() == "mandatory":
            default = ""
        else:
            default = ", " + p.default
        if p.get_type() == "int":
            builder.line("ca::ParameterInt param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        elif p.get_type() == "double":
            builder.line("ca::ParameterDouble param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        elif p.get_type() == "std::string":
            builder.line("ca::ParameterString param::{0}({1}, {2}, {3}{4});",
                         p.name,
                         const_string(p.name),
                         const_string(p.description),
                         policy,
                         default)
        else:
            utils.PtpException("Invalid type '{0}' for parameter '{1}'".format(
                                    p.get_type(), p.name))
Ejemplo n.º 5
0
def parse_init_expression(string, source):
    if string.strip() == "":
        return (None, None)
    try:
        return init_expression.parseString(string, parseAll=True)[0]
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)
Ejemplo n.º 6
0
def split_expressions(string, source):
    if string.strip() == "":
        return []
    try:
        return expressions.parseString(string, parseAll=True)
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)
Ejemplo n.º 7
0
    def run(self):
        builder = build.Builder(self.project,
            os.path.join("/tmp", self.project.get_name() + ".h"))

        build.write_header_file(builder)
        builder.write_to_file()

        tester = base.tester.Tester()
        tester.prepare_writer = self.prepare_writer
        tester.args = [ "-I", os.path.join(paths.KAIRA_ROOT, paths.CAILIE_INCLUDE_DIR),
                        "-I", self.project.root_directory ]

        if self.project.get_build_with_octave():
            import ptp # To avoid cyclic import
            tester.args += [ "-I", os.path.join(paths.KAIRA_ROOT, paths.CAOCTAVE_INCLUDE_DIR) ]
            tester.args += ptp.get_config("Octave", "INCFLAGS").split()

        if self.project.build_target == "simrun":
            tester.args += [ "-I", os.path.join(paths.KAIRA_ROOT, paths.CASIMRUN_INCLUDE_DIR) ]

        tester.args += self.project.get_build_option("CFLAGS").split()
        tester.run()

        if tester.stderr:
            raise utils.PtpException(tester.stderr)

        for t in self.types.values():
            t.add_checks(tester)

        for check in self.checks:
            tester.add(check)

        check = tester.run()
        if check is not None:
            check.throw_exception()
Ejemplo n.º 8
0
def load_area(element, project, net):
    id = utils.xml_int(element, "id")
    init_type, init_value = project.parse_init_expression(
        element.get("init-expr"),
        get_source(element, "init"))
    if init_type is None:
        raise utils.PtpException("Expression is empty", get_source(element, "init"))
    places = [ net.get_place(utils.xml_int(e, "id"))
               for e in element.findall("place") ]
    return Area(net, id, init_type, init_value, places)
Ejemplo n.º 9
0
    def check(self):
        if self.library_octave:
            import ptp # Import here to avoid cyclyc import
            if ptp.get_config("Main", "OCTAVE") != "True":
                raise utils.PtpException("Cannot build a module for Octave, "
                                         "Kaira is not build with Octave support.\n"
                                         "Run './waf configure' in Kaira root directory")

        if self.get_build_with_octave():
            import ptp # Import here to avoid cyclyc import
            if ptp.get_config("Main", "OCTAVE") != "True":
                raise utils.PtpException("Cannot build a project with Octave C++ API, "
                                         "Kaira is not build with Octave support.\n"
                                         "Run './waf configure' in Kaira root directory")

        checker = self.target_env.get_checker(self)
        for net in self.nets:
            net.check(checker)
        checker.run()
Ejemplo n.º 10
0
def parse_expression(expr, source, allow_empty):
    if len(expr.strip()) == 0:
        if allow_empty:
            return None
        else:
            return "Missing expression"
    try:
        return full_expression.parseString(expr, parseAll=True)[0]
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)
Ejemplo n.º 11
0
def write_parameters_forward(builder):
    builder.line("struct param")
    builder.block_begin()
    for p in builder.project.get_parameters():
        if p.get_type() == "int":
            builder.line("static ca::ParameterInt {0};", p.get_name())
        elif p.get_type() == "double":
            builder.line("static ca::ParameterDouble {0};", p.get_name())
        elif p.get_type() == "std::string":
            builder.line("static ca::ParameterString {0};", p.get_name())
        else:
            raise utils.PtpException("Invalid type '{0}' for parameter '{1}'".format(
                                     p.get_type(), p.name))
    builder.write_class_end()
Ejemplo n.º 12
0
def load_transition(element, project, net):
    id = utils.xml_int(element, "id")

    name = element.get("name")
    guard = project.parse_expression(element.get("guard"),
                                     get_source(element, "guard"),
                                     allow_empty=True)
    transition = Transition(net, id, name, guard)
    transition.collective = utils.xml_bool(element, "collective", False)
    transition.edges_in = map(
        lambda e: load_edge_in(e, project, net, transition),
        element.findall("edge-in"))
    transition.edges_out = map(
        lambda e: load_edge_out(e, project, net, transition),
        element.findall("edge-out"))
    if element.find("code") is not None:
        transition.code = element.find("code").text
    transition.trace_fire = element.find("trace") is not None
    transition.clock = utils.xml_bool(element, "clock", False)

    if transition.collective:
        transition.root = project.parse_expression(element.get("root"),
                                                   get_source(element, "root"),
                                                   allow_empty=True)

    if element.find("time-substitution") is not None:
        transition.time_substitution = element.find("time-substitution").text
    if element.find("clock-substitution") is not None:
        transition.clock_substitution = element.find("clock-substitution").text

    if element.find("verif-quit_flag") is not None:
        transition.calls_quit = True
    e = element.find("verif-occurrence")
    if e is not None:
        transition.occurrence_analysis = True
        transition.occurrence_analysis_compare_process = utils.xml_bool(
            e, "process")
        transition.occurrence_analysis_compare_binding = utils.xml_bool(
            e, "binding")

    priority = element.get("priority").strip()
    if priority == "":
        transition.priority = 0
    elif utils.is_integer(priority):
        transition.priority = int(priority)
    else:
        raise utils.PtpException("Priority has to be integer or empty",
                                 get_source(element, "priority"))
    return transition
Ejemplo n.º 13
0
        raise utils.PtpException(e.msg, source)

def parse_init_expression(string, source):
    if string.strip() == "":
        return (None, None)
    try:
        return init_expression.parseString(string, parseAll=True)[0]
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)

def parse_edge_expression(string, source):
    if len(string.strip()) == 0:
        raise utils.PtpException("Missing expression", source)

    try:
        inscriptions = edge_expr.parseString(string, parseAll=True)
    except pp.ParseException, e:
        raise utils.PtpException(e.msg, source)

    results = []
    for configs, expr, target in inscriptions:
        config = {}
        for name, param in configs:
            if name in config:
                raise utils.PtpException(
                    "Configuration option '{0}' used more then once".format(name), source)
            else:
                config[name] = param
        results.append((config, expr, target))
    return results
Ejemplo n.º 14
0
 def throw_exception(self):
     raise utils.PtpException(self.message, self.source)