Example #1
0
    def _fields(self):
        for fnode in self.root.findall("Field[@context='%s']" %
                                       self.node.attrib["id"]):
            access_type = Access.access_type(fnode)

            if access_type == Access.PRIVATE:
                continue

            if access_type == Access.PROTECTED and not self.allows_subclassing(
            ):
                continue

            name = fnode.attrib["name"]

            # union
            if not name:
                continue

            if self.blacklist.field(self.full_name, name):
                full_name = self.full_name + "::" + name
                Session.ignored_fields.add(full_name)
                continue

            t = Types.get_type_by_id(fnode.attrib["type"], self.root)
            f = Argument.Argument(t, name)
            self.fields.append(f)

            if access_type == Access.PROTECTED:
                self.protected_nonvirtual_members.add(
                    "using %s::%s;" % (self.full_name, f.raw_name))
Example #2
0
def _test_fundamental():
    tk = TupleAndKeywords()
    tk.add_parameter(
        Argument.Argument(Types.Type(("int", ), 1, "FundamentalType"), "foo",
                          10))
    tk.add_parameter(
        Argument.Argument(Types.Type(("long int", ), 2, "FundamentalType"),
                          "bar", 20))
    tk.add_parameter(
        Argument.Argument(Types.Type(("int", ), 3, "FundamentalType"), "mit",
                          30))

    print(tk.get_fmt_specifier())
    print(tk.get_keywords())
    print(tk.build_parser_idecl())
    print(tk.build_function_signature_parameter_list())
Example #3
0
    def _constructor(self, ctor):
        logging.debug(ctor.attrib["demangled"])

        tk = TupleAndKeywords.TupleAndKeywords()
        for argn in ctor.findall("Argument"):
            arg = Argument.Argument()
            arg.parse_xml(self.root, argn)
            tk.add_parameter(arg)

            self.fptrs.try_add(arg.type)

        self.ctors.append(tk)
Example #4
0
 def fromUML(self, umlString):
     if umlString[0] == "+":
         self.visi = "public"
     if umlString[0] == "-":
         self.visi = "private"
     umlString = umlString.lstrip("+ ").lstrip("- ")
     umlString = umlString.split(":")
     if len(umlString) > 1:
         self.rtype = umlString[1].lstrip(" ")
     umlString = umlString[0]
     umlString = umlString.split("(")
     self.name = umlString[0]
     if len(umlString) > 1:
         arguments = umlString[1].split(")")[0].split(",")
         if len(arguments[0]) > 0:
             for uml_argument in arguments:
                 argument = Argument()
                 argument.fromUML(uml_argument.lstrip(" "))
                 self.args.append(argument)
 def __parse_argument(self, element):
     argument = Argument.Argument()
     if element.tag[0:3] != "arg":
         print("Argument element tag must start with arg", file=sys.stderr)
         exit(31)
     if not element.tag[3:].isdigit():
         print("Argument element tag must end with digit", file=sys.stderr)
         exit(31)
     argument.set_order(int(element.tag[3:]))
     for key, value in element.items():
         if key == "type":
             argument.set_type(value)
         else:
             print("Argument element must have correct attributes",
                   file=sys.stderr)
             exit(31)
     if not argument.get_type():
         print("Argument element must have type attribute", file=sys.stderr)
         exit(31)
     argument.set_value(element.text)
     return argument
Example #6
0
def _test():
    import CodeBlock
    import Converters
    import HeaderJar

    header_jar = HeaderJar.HeaderJar()
    Session.begin(header_jar)

    Converters.add(Converters.WcsConv())

    tk = TupleAndKeywords()
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "int",
            "*",
        ), 1, "FundamentalType"), "foo"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "double",
            "&",
        ), 2, "FundamentalType"), "bar"))
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "long unsigned int",
                "&",
                "const",
            ), 3, "FundamentalType"), "xyz"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "X",
            "const",
            "&",
        ), 4, "Class"), "x"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "Y",
            "*",
        ), 5, "Class"), "y"))
    tk.add_parameter(Argument.Argument(Types.Type(("Z", ), 6, "Class"), "z"))
    tk.add_parameter(
        Argument.Argument(Types.Type(("bool", ), 7, "FundamentalType"), "b"))
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "wchar_t",
                "const",
                "*",
            ), 8, "PointerType"), "str"))

    print(tk.get_fmt_specifier())
    print(tk.get_keywords())
    print(tk.build_function_signature_parameter_list())

    from Module import PythonNamer
    namer = PythonNamer()

    print(tk.build_parser_idecl(namer=namer))
    _print_empty_line()

    block = CodeBlock.CodeBlock()
    tk.write_args_parsing_code(block, namer, True, "return nullptr;", "<TEST>")

    print(block.flush())
    _print_empty_line()
    _print_empty_line()

    tk = TupleAndKeywords()
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "int",
            "*",
        ), 1, "FundamentalType"), "foo", "nullptr"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "double",
            "&",
        ), 2, "FundamentalType"), "bar", "PI"))
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "long unsigned int",
                "&",
                "const",
            ), 3, "FundamentalType"), "xyz", "MAXINT"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "X",
            "const",
            "&",
        ), 4, "Class"), "x", "_x"))
    tk.add_parameter(
        Argument.Argument(Types.Type((
            "Y",
            "*",
        ), 5, "Class"), "y", "_py"))
    tk.add_parameter(
        Argument.Argument(Types.Type(("Z", ), 6, "Class"), "z", "Z(1990)"))
    tk.add_parameter(
        Argument.Argument(Types.Type(("bool", ), 7, "FundamentalType"), "b",
                          "true"))
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "wchar_t",
                "const",
                "*",
            ), 8, "PointerType"), "str", 'L"Hello world!"'))
    tk.write_args_parsing_code(block, namer, True, "return nullptr;", "<TEST>")

    print(block.flush())

    integer = Types.Type(("int", ), 99, "FundamentalType")
    Converters.add(Converters.ListConv(integer))

    tk = TupleAndKeywords()
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "std::vector<int>",
                "const",
                "&",
            ), 0, "Class"), "vi", "_vi"))
    tk.write_args_parsing_code(block, namer, True, "return nullptr;", "<TEST>")

    print(block.flush())

    K = Types.Type((
        "wchar_t",
        "const",
        "*",
    ), 111, "PointerType")
    V = Types.Type((
        "wxColour",
        "*",
    ), 112, "PointerType")
    Converters.add(Converters.DictConv(K, V))

    tk = TupleAndKeywords()
    tk.add_parameter(
        Argument.Argument(
            Types.Type((
                "std::map<wchar_t const *, wxColour *>",
                "&",
            ), 0, "Class"), "m"))
    tk.write_args_parsing_code(block, namer, True, "return nullptr;", "<TEST>")

    print(block.flush())
Example #7
0
    def __parse_args(self, instruction):
        symb = ["var", "int", "string", "bool"]
        opcode = instruction.get('opcode')
        order = instruction.get('order')
        err_message = "Instruction order = '{0}' ".format(order)
        args_count = len(instruction)

        # <var> <symb>
        if (opcode in ["MOVE", "INT2CHAR", "STRLEN", "TYPE", "NOT"]):
            err_message += "\nInstruction '{0}' expects arguments <var> <symb>".format(
                opcode)
            if (args_count != 2):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'var'):
                raise InstructException(err_message)
            if (instruction[1].get('type') not in symb):
                raise InstructException(err_message)

        # no arguments
        elif (opcode
              in ["CREATEFRAME", "PUSHFRAME", "POPFRAME", "RETURN", "BREAK"]):
            err_message += "\nInstruction '{0}' expects no arguments".format(
                opcode)
            if (args_count != 0):
                raise InstructException(err_message)
        # <var>
        elif (opcode in ["DEFVAR", "POPS"]):
            err_message += "\nInstruction '{0}' expects argument <var>".format(
                opcode)
            if (args_count != 1):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'var'):
                raise InstructException(err_message)
        # <label>
        elif (opcode in ["CALL", "LABEL", "JUMP"]):
            err_message += "\nInstruction '{0}' expects argument <label>".format(
                opcode)
            if (args_count != 1):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'label'):
                raise InstructException(err_message)
        # <symb>
        elif (opcode in ["PUSHS", "WRITE", "DPRINT"]):
            err_message += "\nInstruction '{0}' expects argument <symb>".format(
                opcode)
            if (args_count != 1):
                raise InstructException(err_message)
            if (instruction[0].get('type') not in symb):
                raise InstructException(err_message)
        # <var> <symb1> <symb2>
        elif (opcode in [
                "ADD", "SUB", "MUL", "IDIV", "LT", "GT", "EQ", "AND", "OR",
                "STRI2INT", "CONCAT", "GETCHAR", "SETCHAR"
        ]):
            err_message += ("\nInstruction '{0}' expects arguments "
                            "<var> <symb1> <symb2>".format(opcode))
            if (args_count != 3):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'var'):
                raise InstructException(err_message)
            if (instruction[1].get('type') not in symb):
                raise InstructException(err_message)
            if (instruction[2].get('type') not in symb):
                raise InstructException(err_message)
        # <var> <type>
        elif (opcode == "READ"):
            err_message += ("\nInstruction '{0}' expects arguments "
                            "<var> <type>".format(opcode))
            if (args_count != 2):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'var'):
                raise InstructException(err_message)
            if (instruction[1].get('type') != 'type'):
                raise InstructException(err_message)
        # <label> <symb1> <symb2>
        elif (opcode in ["JUMPIFEQ", "JUMPIFNEQ"]):
            err_message += ("\nInstruction '{0}' expects arguments "
                            "<label> <symb1> <symb2>".format(opcode))
            if (args_count != 3):
                raise InstructException(err_message)
            if (instruction[0].get('type') != 'label'):
                raise InstructException(err_message)
            if (instruction[1].get('type') not in symb):
                raise InstructException(err_message)
            if (instruction[2].get('type') not in symb):
                raise InstructException(err_message)
        else:
            err_message += "\nUnknown instruction '{0}'".format(opcode)
            raise InstructException(err_message)

        for arg in instruction:
            self.__arguments.append(Argument.Argument(arg))
Example #8
0
import sys, getopt
from Argument import *

if __name__ == "__main__":
    handler = ArgumentsHandler(
        Argument("help", "help", "h", False, "provides Help"),
        Argument("test", "test", "t", description="Testing"))
    result = handler.resolve(sys.argv)
    print(result)