Exemple #1
0
	def __init__(self, hardware_arch, generator_type, cpp = None, idl_cpp = None,
			cpp_options = None, cpp_include_dirs = None, cpp_defines = None):

		self.basicast = create_basictype_ast(hardware_arch, generator_type)
		self.inputparser = inputparser_construct(cpp = cpp, idl_cpp = idl_cpp,
				cpp_options = cpp_options, include_dirs = cpp_include_dirs,
				defines = cpp_defines)
Exemple #2
0
	def _parse_pt_to_ast(self, pt, filename, data, output, options = None):
		basicast = create_basictype_ast(options['hardware_arch'], options['generator'])
		for child in basicast.children:
			child.nonprinting = True
		try:
			basicast = parse_to_ast(pt, filename, basicast)
		except ParserError, e:
			print >>output, "* Semantic error *"
			print >>output, str(e)
	def _parse_pt_to_ast(self, pt, filename, data, output, options = None):
		basicast = create_basictype_ast(options['hardware_arch'], options['generator'])
		for child in basicast.children:
			child.nonprinting = True
		try:
			basicast = parse_to_ast(pt, filename, basicast)
		except ParserError, e:
			print >>output, "* Semantic error *"
			print >>output, str(e)
Exemple #4
0
def main():
	# Parse command-line arguments and dispatch to appropriate tester.
	parser = OptionParser()
	#parser_inst.setup()
	parser.add_option('--pt', dest = "pt", action = 'store_true', default = False,
			help = 'Display the IDL parse tree')
	parser.add_option('--ast', dest = 'ast', action = 'store_true', default = False,
			help = 'Display the IDL AST')
	parser.add_option('--ast-pl', dest = 'ast_pl', action = 'store_true', default = False,
			help = 'Display the IDL AST in a Prolog-friendly format')
	parser.add_option('--types', dest = 'types', action = 'store_true', default = False,
			help = 'Import types and display the type registry')
	parser.add_option('--no-basic', dest = 'no_basic', action = 'store_true',
			default = False, help = 'Do not AST display basic types')
	cmdlineoptions, cmdlineargs = parser.parse_args()

	if cmdlineargs == []: # No files, so exit
		parser.print_help()
		print >>sys.stderr, "\nExiting because no IDL files were specified.\n"
		sys.exit(1)
	elif len(cmdlineargs) > 1: # Too many files!
		parser.print_help()
		print >>sys.stderr, "\nExiting because more than 1 IDL file was specified.\n"
		sys.exit(1)
		
	#if cmdlineoptions.ugly_includepath_hack is not None:
	#	cmdlineoptions.include_dirs = [os.path.join(cmdlineoptions.ugly_includepath_hack, i)
	#		for i in cmdlineoptions.include_dirs]

	hardware_arch = 'Generic 32'
	generator_type = 'idl4'
		
	pt = parse_to_pt(cmdlineargs[0])
	
	if cmdlineoptions.pt:
		print "*** PT:"
		pt.print_tree()
		print "*** PT ends"
	
	if cmdlineoptions.ast or cmdlineoptions.ast_pl:
		basicast = create_basictype_ast(hardware_arch, generator_type)
		if cmdlineoptions.no_basic:
			for child in basicast.children:
				child.nonprinting = True
			name = 'AST (no basic types)'
		else:
			name = 'AST'
		
		basicast = parse_to_ast(pt, cmdlineargs, basicast)
		if cmdlineoptions.ast:
			print "*** %s:" % (name)
			basicast.print_tree(hide_hidden = True)
			print "*** AST ends"
		else:
			assert cmdlineoptions.ast_pl
			print_tree_pl(basicast)
Exemple #5
0
def parse(filename, cpp_options=None, use_cpp=True, accelerate=False, **kwargs):
    if use_cpp:
        pt = parse_to_pt(filename, cpp_options, accelerate=accelerate)
    else:
        data = gethandle(filename).read()
        pt = parse_data_to_pt(filename, data)

        # Create the standard C/C++ AST.
    basicast = create_basictype_ast("Generic 32", "idl4")
    # Create AST and return.
    return parse_to_ast(basicast, pt, filename, **kwargs)
Exemple #6
0
    def test_gridparameters(self):
        GRIDPARAMS = [
            ('void', 'in int arg', ['box 0:0 param arg:0-32'], []),
            ('void', 'in int arg1, in int arg2',
             ['box 0:0 param arg1:0-32', 'box 1:0 param arg2:0-32'], []),
            ('short', 'in short arg1, in int arg2, out short arg3',
             ['box 0:0 param arg1:0-16', 'box 1:0 param arg2:0-32'
              ], ['box 0:0 param arg3:0-16', 'box 0:16 param __retval:0-16']),
            ('int', 'in int y', ['box 0:0 param y:0-32'],
             ['box 0:0 param __retval:0-32']),
        ]
        inputparser = inputparser_construct()
        for retval, testparams, output_dirin, output_dirout in GRIDPARAMS:
            # Create the test file, so the rest of the system can survive...
            # We use mkstemp because Windows NT can't reopen regular temp files
            test_string = CANNED_INTERFACE % (retval, testparams)
            handle, pathname = tempfile.mkstemp()
            try:
                os.write(handle, test_string)
                os.close(handle)

                # Now to create the AST
                basicast = create_basictype_ast(HARDWARE_ARCH, GENERATOR_TYPE)
                ast = inputparser.produce_ast(pathname, 'CORBA', basicast)
                astinfo = ASTInfo(ast)

                # Get a generator
                generator = V4Generator(GenericOutput(), astinfo)

                # And walk to the function.
                interface = list(generator.get_interfaces())[0]
                function = list(interface.get_functions())[0]
                marshal = self._rewrite_grid(function, ['in', 'inout'])
                unmarshal = self._rewrite_grid(function,
                                               ['inout', 'out', 'return'])

                fail = False

                if marshal != output_dirin:
                    print "\nmarshal_c: %s\nvs %s\n" % (marshal, output_dirin)
                    fail = True

                if unmarshal != output_dirout:
                    print "\nunmarshal_c: %s\nvs %s\n" % (unmarshal,
                                                          output_dirout)
                    fail = True

                self.assert_(marshal == output_dirin
                             and unmarshal == output_dirout)

            finally:
                os.unlink(pathname)
Exemple #7
0
def parse(filename,
          cpp_options=None,
          use_cpp=True,
          accelerate=False,
          **kwargs):
    if use_cpp:
        pt = parse_to_pt(filename, cpp_options, accelerate=accelerate)
    else:
        data = gethandle(filename).read()
        pt = parse_data_to_pt(filename, data)

    # Create the standard C/C++ AST.
    basicast = create_basictype_ast('Generic 32', 'idl4')
    # Create AST and return.
    return parse_to_ast(basicast, pt, filename, **kwargs)
Exemple #8
0
	def test_gridparameters(self):
		GRIDPARAMS = [
			('void', 'in int arg', ['box 0:0 param arg:0-32'], []),
			('void', 'in int arg1, in int arg2', ['box 0:0 param arg1:0-32', 'box 1:0 param arg2:0-32'], []),
			('short', 'in short arg1, in int arg2, out short arg3', ['box 0:0 param arg1:0-16', 'box 1:0 param arg2:0-32'], ['box 0:0 param arg3:0-16', 'box 0:16 param __retval:0-16']),
			('int', 'in int y', ['box 0:0 param y:0-32'], ['box 0:0 param __retval:0-32']),
		]
		inputparser = inputparser_construct()
		for retval, testparams, output_dirin, output_dirout in GRIDPARAMS:
			# Create the test file, so the rest of the system can survive...
			# We use mkstemp because Windows NT can't reopen regular temp files
			test_string = CANNED_INTERFACE % (retval, testparams)
			handle, pathname = tempfile.mkstemp()
			try:
				os.write(handle, test_string)
				os.close(handle)

				# Now to create the AST
				basicast = create_basictype_ast(HARDWARE_ARCH, GENERATOR_TYPE)
				ast = inputparser.produce_ast(pathname, 'CORBA', basicast)
				astinfo = ASTInfo(ast)

				# Get a generator
				generator = V4Generator(GenericOutput(), astinfo)

				# And walk to the function.
				interface = list(generator.get_interfaces())[0]
				function = list(interface.get_functions())[0]
				marshal = self._rewrite_grid(function, ['in', 'inout'])
				unmarshal = self._rewrite_grid(function, ['inout', 'out', 'return'])

				fail = False

				if marshal != output_dirin:
					print "\nmarshal_c: %s\nvs %s\n" % (marshal, output_dirin)
					fail = True

				if unmarshal != output_dirout:
					print "\nunmarshal_c: %s\nvs %s\n" % (unmarshal, output_dirout)
					fail = True

				self.assert_(marshal == output_dirin and unmarshal == output_dirout)

			finally:
				os.unlink(pathname)
Exemple #9
0
def main():
	# Parse command-line arguments and dispatch to appropriate tester.
	parser = OptionParser()
	parser.add_option('--cpp', dest = 'use_cpp', action = 'store_true', default = False,
			help = 'Preprocess the source file')
	parser.add_option('--pt', dest = 'pt', action = 'store_true', default = False,
			help = 'Display the C++ parse tree')
	parser.add_option('--ast', dest = 'ast', action = 'store_true', default = False,
			help = 'Display the C++ AST')
	parser.add_option('--types', dest = 'types', action = 'store_true', default = False,
			help = 'Import types and display the type registry')
	parser.add_option('--profile', dest = 'profile', action = 'store_true', default = False,
			help = 'Perform several parses and produce a report')
	parser.add_option('--magpie', dest = 'magpie_mode', action = 'store_true', default = False,
			help = 'Only test type generation (simulates magpie.py use)')
	parser.add_option('--pickle-pt', dest = 'pickle_pt', action = 'store', default = None,
			help = 'Pickle parse tree to named file')
	parser.add_option('--slow-parser', dest = 'slow_parser', action = 'store_true', default = False,
			help = 'Use the Python C++ parser (slow but does not require C extension)')
	my_options, args = parser.parse_args()

	if len(args) != 1:
		print >>sys.stderr, "Please specify one C file for processing.\n"
		sys.exit(1)

	filename = args[0]
	
	data = file(filename).read()

	if my_options.profile:
		loops = 5
	else:
		loops = 1
	
	accelerate = True
	if my_options.slow_parser:
		accelerate = False

	if my_options.pickle_pt and accelerate:
		print "*** Disabling acceleration for pickling"
		accelerate = False

	for count in range(loops):
		pt = parse_to_pt(filename, accelerate = accelerate)

	if my_options.pt:
		print "*** Parse tree:"
		pt.print_tree()
		print "*** Parse tree ends"
	
	if my_options.pickle_pt is not None:
		handle = file(my_options.pickle_pt, 'wb')
		cPickle.dump(pt, handle)
		handle.close()
		print "*** Wrote pickle to %s" % (my_options.pickle_pt)
	
	hardware_arch = 'Generic 32'
	generator_type = 'idl4'

	if my_options.ast:
		basicast = create_basictype_ast(hardware_arch, generator_type)
		if my_options.magpie_mode:
			types_only = True
			experimental = False
		else:
			experimental = True
			types_only = False

		ast = parse_to_ast(basicast, pt, filename, types_only = types_only,
				experimental = experimental)
		print "*** AST:"
		ast.print_tree()
		print "*** AST ends"

	if my_options.types and ast:
		#registry = gimme_a_registry()
		#walker = CASTWalker(registry)
		#walker.find_types(ast)

	
		print "*** Types list:"
		#registry.print_registry()
		print "*** Types list ends"
Exemple #10
0
def main():
    # Parse command-line arguments and dispatch to appropriate tester.
    parser = OptionParser()
    #parser_inst.setup()
    parser.add_option('--pt',
                      dest="pt",
                      action='store_true',
                      default=False,
                      help='Display the IDL parse tree')
    parser.add_option('--ast',
                      dest='ast',
                      action='store_true',
                      default=False,
                      help='Display the IDL AST')
    parser.add_option('--ast-pl',
                      dest='ast_pl',
                      action='store_true',
                      default=False,
                      help='Display the IDL AST in a Prolog-friendly format')
    parser.add_option('--types',
                      dest='types',
                      action='store_true',
                      default=False,
                      help='Import types and display the type registry')
    parser.add_option('--no-basic',
                      dest='no_basic',
                      action='store_true',
                      default=False,
                      help='Do not AST display basic types')
    cmdlineoptions, cmdlineargs = parser.parse_args()

    if cmdlineargs == []:  # No files, so exit
        parser.print_help()
        print >> sys.stderr, "\nExiting because no IDL files were specified.\n"
        sys.exit(1)
    elif len(cmdlineargs) > 1:  # Too many files!
        parser.print_help()
        print >> sys.stderr, "\nExiting because more than 1 IDL file was specified.\n"
        sys.exit(1)

    #if cmdlineoptions.ugly_includepath_hack is not None:
    #	cmdlineoptions.include_dirs = [os.path.join(cmdlineoptions.ugly_includepath_hack, i)
    #		for i in cmdlineoptions.include_dirs]

    hardware_arch = 'Generic 32'
    generator_type = 'idl4'

    pt = parse_to_pt(cmdlineargs[0])

    if cmdlineoptions.pt:
        print "*** PT:"
        pt.print_tree()
        print "*** PT ends"

    if cmdlineoptions.ast or cmdlineoptions.ast_pl:
        basicast = create_basictype_ast(hardware_arch, generator_type)
        if cmdlineoptions.no_basic:
            for child in basicast.children:
                child.nonprinting = True
            name = 'AST (no basic types)'
        else:
            name = 'AST'

        basicast = parse_to_ast(pt, cmdlineargs, basicast)
        if cmdlineoptions.ast:
            print "*** %s:" % (name)
            basicast.print_tree(hide_hidden=True)
            print "*** AST ends"
        else:
            assert cmdlineoptions.ast_pl
            print_tree_pl(basicast)
Exemple #11
0
def main():
    # Parse command-line arguments and dispatch to appropriate tester.
    parser = OptionParser()
    parser.add_option('--cpp',
                      dest='use_cpp',
                      action='store_true',
                      default=False,
                      help='Preprocess the source file')
    parser.add_option('--pt',
                      dest='pt',
                      action='store_true',
                      default=False,
                      help='Display the C++ parse tree')
    parser.add_option('--ast',
                      dest='ast',
                      action='store_true',
                      default=False,
                      help='Display the C++ AST')
    parser.add_option('--types',
                      dest='types',
                      action='store_true',
                      default=False,
                      help='Import types and display the type registry')
    parser.add_option('--profile',
                      dest='profile',
                      action='store_true',
                      default=False,
                      help='Perform several parses and produce a report')
    parser.add_option(
        '--magpie',
        dest='magpie_mode',
        action='store_true',
        default=False,
        help='Only test type generation (simulates magpie.py use)')
    parser.add_option('--pickle-pt',
                      dest='pickle_pt',
                      action='store',
                      default=None,
                      help='Pickle parse tree to named file')
    parser.add_option(
        '--slow-parser',
        dest='slow_parser',
        action='store_true',
        default=False,
        help='Use the Python C++ parser (slow but does not require C extension)'
    )
    my_options, args = parser.parse_args()

    if len(args) != 1:
        print >> sys.stderr, "Please specify one C file for processing.\n"
        sys.exit(1)

    filename = args[0]

    data = file(filename).read()

    if my_options.profile:
        loops = 5
    else:
        loops = 1

    accelerate = True
    if my_options.slow_parser:
        accelerate = False

    if my_options.pickle_pt and accelerate:
        print "*** Disabling acceleration for pickling"
        accelerate = False

    for count in range(loops):
        pt = parse_to_pt(filename, accelerate=accelerate)

    if my_options.pt:
        print "*** Parse tree:"
        pt.print_tree()
        print "*** Parse tree ends"

    if my_options.pickle_pt is not None:
        handle = file(my_options.pickle_pt, 'wb')
        cPickle.dump(pt, handle)
        handle.close()
        print "*** Wrote pickle to %s" % (my_options.pickle_pt)

    hardware_arch = 'Generic 32'
    generator_type = 'idl4'

    if my_options.ast:
        basicast = create_basictype_ast(hardware_arch, generator_type)
        if my_options.magpie_mode:
            types_only = True
            experimental = False
        else:
            experimental = True
            types_only = False

        ast = parse_to_ast(basicast,
                           pt,
                           filename,
                           types_only=types_only,
                           experimental=experimental)
        print "*** AST:"
        ast.print_tree()
        print "*** AST ends"

    if my_options.types and ast:
        #registry = gimme_a_registry()
        #walker = CASTWalker(registry)
        #walker.find_types(ast)

        print "*** Types list:"
        #registry.print_registry()
        print "*** Types list ends"