def getInterfacesFromFile(filename, includepath=None): popen_cmd = main.preprocessor_cmd if includepath: for newpath in includepath: popen_cmd += ' -I "' + newpath + '"' popen_cmd += ' "' + filename + '"' f = os.popen(popen_cmd, 'r') try: tree = _omniidl.compile(f) except TypeError: tree = _omniidl.compile(f, filename) try: ints = run(tree,'') except: #print popen_cmd #print filename pass f.close() del tree idlast.clear() idltype.clear() _omniidl.clear() #store file name and location information for each interface for x in ints: x.fullpath = filename i = filename.rfind("/") if i >= 0: x.filename = filename[i+1:] x.filename = x.filename[:-4] #remove the .idl suffix return ints
def getInterfaces(filename): f = os.popen(main.preprocessor_cmd + ' -I "/usr/local/include" -I "/usr/local/include/ossie" -I "/usr/include" "' \ + filename + '"','r') try: tree = _omniidl.compile(f, filename) except TypeError: tree = _omniidl.compile(f) ints = run(tree,'') f.close() del tree idlast.clear() idltype.clear() _omniidl.clear() #store file name and location information for each interface for x in ints: x.fullpath = filename i = filename.rfind("/") if i >= 0: x.filename = filename[i+1:] x.filename = x.filename[:-4] #remove the .idl suffix return ints
def generate(idl_file, preproc_args, impl_suffix, skel_suffix = "Skel", fd_h=None, fd_cpp=None): basename = idl_file.replace(".idl","") preprocessor_cmd = "omnicpp" preprocessor_opt = "-I" + string.join(preproc_args, " -I") preproc_cmd = '%s %s %s' % (preprocessor_cmd,\ preprocessor_opt, idl_file) file = os.popen(preproc_cmd, "r") skel_filename = basename + skel_suffix + ".h" idl_filename = idl_file # ignore the following operations ignore_operations = ["profile"] tree = _omniidl.compile(file) ast.__init__(tree) cxx_svc_impl.__init__(idl_filename, \ basename, \ skel_filename, \ impl_suffix, \ ignore_operations, \ fd_h, \ fd_cpp) ifs = cxx_svc_impl.run(tree) file.close() _omniidl.clear() return ifs
def parse(ir, cppfile, src, primary_file_only, base_path, verbose, debug): global basename, strip, sourcefile if base_path: basename = base_path _omniidl.keepComments(1) _omniidl.noForwardWarning() tree = _omniidl.compile(open(cppfile, 'r+')) if tree == None: sys.stderr.write("omni: Error parsing %s\n"%cppfile) sys.exit(1) sourcefile = SourceFile(strip_filename(src), src, 'IDL') sourcefile.annotations['primary'] = True new_ir = IR.IR() new_ir.files[sourcefile.name] = sourcefile type_trans = TypeTranslator(new_ir.asg.types) ast_trans = ASGTranslator(new_ir.asg.declarations, type_trans, primary_file_only) tree.accept(ast_trans) sourcefile.declarations[:] = new_ir.asg.declarations ir.merge(new_ir) _omniidl.clear() return ir
def idlfile_scan(node, env, path): include_args = ['-I' + directory for directory in env['IDL_INCLUDE_PATH']] try: idl = parseOmniIdlArgs(include_args + [str(node)]) idl_dependencies = [] for module in idl.declarations(): if (module.file() != idl.file()) and (module.file() not in idl_dependencies): idl_dependencies.append(module.file()) idlast.clear() idltype.clear() _omniidl.clear() search_dirs = tuple([env.Dir(dirname) for dirname in env['IDL_INCLUDE_PATH']]) idl_dependencies = [SCons.Node.FS.find_file(idlname, search_dirs) for idlname in idl_dependencies] return idl_dependencies except Exception: return []
def idlfile_scan(node, env, path): include_args = ['-I' + directory for directory in env['IDL_INCLUDE_PATH']] try: idl = parseOmniIdlArgs(include_args + [str(node)]) idl_dependencies = [] for module in idl.declarations(): if (module.file() != idl.file()) and (module.file() not in idl_dependencies): idl_dependencies.append(module.file()) idlast.clear() idltype.clear() _omniidl.clear() search_dirs = tuple( [env.Dir(dirname) for dirname in env['IDL_INCLUDE_PATH']]) idl_dependencies = [ SCons.Node.FS.find_file(idlname, search_dirs) for idlname in idl_dependencies ] return idl_dependencies except Exception: return []
except TypeError: tree = _omniidl.compile(f, filename) try: ints = run(tree, '') except Exception, e: print e ints = [] #print popen_cmd #print filename pass f.close() del tree idlast.clear() idltype.clear() _omniidl.clear() #store file name and location information for each interface for x in ints: x.fullpath = filename i = filename.rfind("/") if i >= 0: x.filename = filename[i + 1:] x.filename = x.filename[:-4] #remove the .idl suffix return ints def getInterfacesFromFileAsString(filename, includepath=None): ints = getInterfacesFromFile(filename, includepath) ifaces = ""
except TypeError: tree = _omniidl.compile(f, filename) try: ints = run(tree,'') except Exception, e: print e ints = [] #print popen_cmd #print filename pass f.close() del tree idlast.clear() idltype.clear() _omniidl.clear() #store file name and location information for each interface for x in ints: x.fullpath = filename i = filename.rfind("/") if i >= 0: x.filename = filename[i+1:] x.filename = x.filename[:-4] #remove the .idl suffix return ints def getInterfacesFromFileAsString(filename, includepath=None): ints = getInterfacesFromFile(filename, includepath) ifaces = "" for x in ints:
def idlj_emitter(target, source, env): tlist, slist = [], source # source list is unchanged for src in source: trgs = [] idl_file = str(src) include_args = ['-I' + directory for directory in env['IDL_INCLUDE_PATH']] idl = parseOmniIdlArgs(include_args + [idl_file]) modules = [instance for instance in idl.declarations() if (instance.__class__==idlast.Module) and (instance.file()==idl_file)] ffixes = [('', 'Helper.java'), ('', 'Holder.java')] single_ffix = [('', '.java')] if_ffixes = [('', 'Operations.java'), ('', 'POA.java'), ('', 'POATie.java'), ('_', 'Stub.java')] for module in modules: module_name = module.scopedName()[0] typedefs = [definition for definition in module.definitions() if definition.__class__==idlast.Typedef] interfaces = [definition for definition in module.definitions() if definition.__class__==idlast.Interface] enums = [definition for definition in module.definitions() if definition.__class__==idlast.Enum] exceptions = [definition for definition in module.definitions() if definition.__class__==idlast.Exception] structs = [definition for definition in module.definitions() if definition.__class__==idlast.Struct] consts = [definition for definition in module.definitions() if definition.__class__==idlast.Const] #print [definition.__class__ for definition in module.definitions()] for interface in interfaces: interface_label = interface.scopedName()[-1] trgs += [os.path.join(module_name, prefix + interface_label + suffix) for prefix, suffix in ffixes + single_ffix + if_ffixes] for typedef in typedefs: typedef_label = typedef.declarators()[0].scopedName()[-1] scannage = scanTypedef(src.get_contents(), typedef)[0] if scannage.startswith('sequence'): #print "scannage starts with sequence", scannage trgs += [os.path.join(module_name, prefix + typedef_label + suffix) for prefix, suffix in ffixes] elif typedefIsArray(src.get_contents(), typedef): trgs += [os.path.join(module_name, prefix + typedef_label + suffix) for prefix, suffix in ffixes] else: trgs += [os.path.join(module_name, typedef_label + 'Helper.java')] struct_label = scanTypedefForStruct(src.get_contents(), typedef) if struct_label: trgs += [os.path.join(module_name, prefix + struct_label + suffix) for prefix, suffix in ffixes + single_ffix] for enum in enums: enum_label = enum.scopedName()[-1] trgs += [os.path.join(module_name, prefix + enum_label + suffix) for prefix, suffix in ffixes + single_ffix] for exception in exceptions: exception_label = exception.scopedName()[-1] trgs += [os.path.join(module_name, prefix + exception_label + suffix) for prefix, suffix in ffixes + single_ffix] for struct in structs: struct_label = struct.scopedName()[-1] trgs += [os.path.join(module_name, prefix + struct_label + suffix) for prefix, suffix in ffixes + single_ffix] for const in consts: const_label = const.scopedName()[-1] trgs += [os.path.join(module_name, const_label + '.java')] idlast.clear() idltype.clear() _omniidl.clear() try: package_name = os.path.basename(idl_file)[:-4] package_path = os.path.join(*tuple(env['PKGPREFIX'].split('.'))) trgs = [os.path.join(env['IDL_INSTALL_DIRECTORY'], package_path, file) for file in trgs] except KeyError: trgs = [os.path.join(env['IDL_INSTALL_DIRECTORY'], file) for file in trgs] tlist += trgs print 'target:', tlist, '\nsource:', [str(file) for file in source] # return tlist, slist return tlist, source
def main(argv=None): global preprocessor_args, preprocessor_only, preprocessor_cmd global no_preprocessor, backend, backend_args, dump_only, cd_to global verbose, quiet, print_usage, interactive, temp_file if argv is None: argv = sys.argv files = parseArgs(argv[1:]) if _omniidl.alwaysTempFile(): temp_file = genTempFileName() if print_usage: usage() elif len(files) == 0: if not quiet: sys.stderr.write(cmdname + ": No files specified. Use '" \ + cmdname + " -u' for usage.\n") sys.exit(1) # Import back-ends, and add any pre-processor arguments bemodules = [] for backend in backends: if verbose: sys.stderr.write(cmdname + ": Importing back-end '" +\ backend + "'\n") try: be = be_import(backend) except ImportError as msg: if not quiet: sys.stderr.write(cmdname + \ ": Could not import back-end '" + \ backend + "'\n") sys.stderr.write(cmdname + \ ": Maybe you need to use the -p option?\n") sys.stderr.write(cmdname + \ ": (The error was '" + str(msg) + "')\n") sys.exit(1) if verbose: if hasattr(be, "__file__"): sys.stderr.write(cmdname + ": '" + backend + \ "' imported from '" + be.__file__ + "'\n") else: sys.stderr.write(cmdname + ": '" + backend + \ "' imported from unknown file\n") bemodules.append(be) if hasattr(be, "cpp_args"): preprocessor_args.extend(be.cpp_args) if print_usage and hasattr(be, "usage_string"): print("\nArguments for back-end '" + backend + "':\n") print(be.usage_string) if print_usage: sys.exit(0) if len(backends) == 0 and \ not (quiet or dump_only or preprocessor_only or interactive): sys.stderr.write(cmdname + ": Warning: No back-ends specified; " \ "checking IDL for validity\n") for name in files: if name != "-" and not os.path.isfile(name): if not quiet: sys.stderr.write(cmdname + ": '" + name + "' does not exist\n") sys.exit(1) if sys.platform != 'OpenVMS' or len(preprocessor_args) == 0: preproc_cmd = '%s %s "%s"' % (preprocessor_cmd, " ".join(preprocessor_args), name) else: preproc_cmd = '%s "%s" %s' % (preprocessor_cmd, '" "'.join(preprocessor_args), name) if not no_preprocessor: if verbose: sys.stderr.write(cmdname + ": Preprocessing '" +\ name + "' with '" + preproc_cmd + "'\n") if preprocessor_only: err = os.system(preproc_cmd) if err: if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") sys.exit(1) sys.exit(0) if temp_file: if verbose: sys.stderr.write(cmdname + \ ": cpp output to temporary file '" + \ temp_file + "'\n") err = os.system(preproc_cmd + " >" + temp_file) if err: if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") try: os.remove(temp_file) except: pass sys.exit(1) file = temp_file else: file = os.popen(preproc_cmd, "r") else: # No preprocessor file = name if verbose: sys.stderr.write(cmdname + ": Running front end\n") if dump_only: if verbose: sys.stderr.write(cmdname + ": Dumping\n") _omniidl.dump(file, name) if not isinstance(file, StringType): file.close() if temp_file: os.remove(temp_file) else: tree = _omniidl.compile(file, name) if not isinstance(file, StringType): if file.close(): if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") sys.exit(1) if tree is None: sys.exit(1) if cd_to is not None: old_wd = os.getcwd() os.chdir(cd_to) i = 0 for backend in backends: if verbose: sys.stderr.write(cmdname + ": Running back-end '" +\ backend + "'\n") bemodules[i].run(tree, backends_args[i]) i = i + 1 if interactive: if verbose: sys.stderr.write(cmdname + ": Entering interactive loop\n") idlast.tree = tree _omniidl.runInteractiveLoop() del idlast.tree if cd_to is not None: os.chdir(old_wd) if temp_file and not no_preprocessor: os.remove(temp_file) idlast.clear() idltype.clear() _omniidl.clear()
def main(argv=None): global preprocessor_args, preprocessor_only, preprocessor_cmd global no_preprocessor, backend, backend_args, dump_only, cd_to global verbose, quiet, print_usage, interactive, temp_file if argv is None: argv = sys.argv files = parseArgs(argv[1:]) if _omniidl.alwaysTempFile(): temp_file = genTempFileName() if print_usage: usage() elif len(files) == 0: if not quiet: sys.stderr.write(cmdname + ": No files specified. Use '" \ + cmdname + " -u' for usage.\n") sys.exit(1) # Import back-ends, and add any pre-processor arguments bemodules = [] for backend in backends: if verbose: sys.stderr.write(cmdname + ": Importing back-end '" +\ backend + "'\n") try: be = be_import(backend) except ImportError as msg: if not quiet: sys.stderr.write(cmdname + \ ": Could not import back-end '" + \ backend + "'\n") sys.stderr.write(cmdname + \ ": Maybe you need to use the -p option?\n") sys.stderr.write(cmdname + \ ": (The error was '" + str(msg) + "')\n") sys.exit(1) if verbose: if hasattr(be, "__file__"): sys.stderr.write(cmdname + ": '" + backend + \ "' imported from '" + be.__file__ + "'\n") else: sys.stderr.write(cmdname + ": '" + backend + \ "' imported from unknown file\n") bemodules.append(be) if hasattr(be, "cpp_args"): preprocessor_args.extend(be.cpp_args) if print_usage and hasattr(be, "usage_string"): print("\nArguments for back-end '" + backend + "':\n") print(be.usage_string) if print_usage: sys.exit(0) if len(backends) == 0 and \ not (quiet or dump_only or preprocessor_only or interactive): sys.stderr.write(cmdname + ": Warning: No back-ends specified; " \ "checking IDL for validity\n") for name in files: if name != "-" and not os.path.isfile(name): if not quiet: sys.stderr.write(cmdname + ": '" + name + "' does not exist\n") sys.exit(1) if sys.platform != 'OpenVMS' or len(preprocessor_args)==0: preproc_cmd = '%s %s "%s"' % (preprocessor_cmd, " ".join(preprocessor_args), name) else: preproc_cmd = '%s "%s" %s' % (preprocessor_cmd, '" "'.join(preprocessor_args), name) if not no_preprocessor: if verbose: sys.stderr.write(cmdname + ": Preprocessing '" +\ name + "' with '" + preproc_cmd + "'\n") if preprocessor_only: err = os.system(preproc_cmd) if err: if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") sys.exit(1) sys.exit(0) if temp_file: if verbose: sys.stderr.write(cmdname + \ ": cpp output to temporary file '" + \ temp_file + "'\n") err = os.system(preproc_cmd + " >" + temp_file) if err: if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") try: os.remove(temp_file) except: pass sys.exit(1) file = temp_file else: file = os.popen(preproc_cmd, "r") else: # No preprocessor file = name if verbose: sys.stderr.write(cmdname + ": Running front end\n") if dump_only: if verbose: sys.stderr.write(cmdname + ": Dumping\n") _omniidl.dump(file, name) if not isinstance(file, StringType): file.close() if temp_file: os.remove(temp_file) else: tree = _omniidl.compile(file, name) if not isinstance(file, StringType): if file.close(): if not quiet: sys.stderr.write(cmdname + \ ": Error running preprocessor\n") sys.exit(1) if tree is None: sys.exit(1) if cd_to is not None: old_wd = os.getcwd() os.chdir(cd_to) i = 0 for backend in backends: if verbose: sys.stderr.write(cmdname + ": Running back-end '" +\ backend + "'\n") bemodules[i].run(tree, backends_args[i]) i = i + 1 if interactive: if verbose: sys.stderr.write(cmdname + ": Entering interactive loop\n") idlast.tree = tree _omniidl.runInteractiveLoop() del idlast.tree if cd_to is not None: os.chdir(old_wd) if temp_file and not no_preprocessor: os.remove(temp_file) idlast.clear() idltype.clear() _omniidl.clear()
def idlj_emitter(target, source, env): tlist, slist = [], source # source list is unchanged for src in source: trgs = [] idl_file = str(src) include_args = [ '-I' + directory for directory in env['IDL_INCLUDE_PATH'] ] idl = parseOmniIdlArgs(include_args + [idl_file]) modules = [ instance for instance in idl.declarations() if (instance.__class__ == idlast.Module) and ( instance.file() == idl_file) ] ffixes = [('', 'Helper.java'), ('', 'Holder.java')] single_ffix = [('', '.java')] if_ffixes = [('', 'Operations.java'), ('', 'POA.java'), ('', 'POATie.java'), ('_', 'Stub.java')] for module in modules: module_name = module.scopedName()[0] typedefs = [ definition for definition in module.definitions() if definition.__class__ == idlast.Typedef ] interfaces = [ definition for definition in module.definitions() if definition.__class__ == idlast.Interface ] enums = [ definition for definition in module.definitions() if definition.__class__ == idlast.Enum ] exceptions = [ definition for definition in module.definitions() if definition.__class__ == idlast.Exception ] structs = [ definition for definition in module.definitions() if definition.__class__ == idlast.Struct ] consts = [ definition for definition in module.definitions() if definition.__class__ == idlast.Const ] #print [definition.__class__ for definition in module.definitions()] for interface in interfaces: interface_label = interface.scopedName()[-1] trgs += [ os.path.join(module_name, prefix + interface_label + suffix) for prefix, suffix in ffixes + single_ffix + if_ffixes ] for typedef in typedefs: typedef_label = typedef.declarators()[0].scopedName()[-1] scannage = scanTypedef(src.get_contents(), typedef)[0] if scannage.startswith('sequence'): #print "scannage starts with sequence", scannage trgs += [ os.path.join(module_name, prefix + typedef_label + suffix) for prefix, suffix in ffixes ] elif typedefIsArray(src.get_contents(), typedef): trgs += [ os.path.join(module_name, prefix + typedef_label + suffix) for prefix, suffix in ffixes ] else: trgs += [ os.path.join(module_name, typedef_label + 'Helper.java') ] struct_label = scanTypedefForStruct( src.get_contents(), typedef) if struct_label: trgs += [ os.path.join(module_name, prefix + struct_label + suffix) for prefix, suffix in ffixes + single_ffix ] for enum in enums: enum_label = enum.scopedName()[-1] trgs += [ os.path.join(module_name, prefix + enum_label + suffix) for prefix, suffix in ffixes + single_ffix ] for exception in exceptions: exception_label = exception.scopedName()[-1] trgs += [ os.path.join(module_name, prefix + exception_label + suffix) for prefix, suffix in ffixes + single_ffix ] for struct in structs: struct_label = struct.scopedName()[-1] trgs += [ os.path.join(module_name, prefix + struct_label + suffix) for prefix, suffix in ffixes + single_ffix ] for const in consts: const_label = const.scopedName()[-1] trgs += [os.path.join(module_name, const_label + '.java')] idlast.clear() idltype.clear() _omniidl.clear() try: package_name = os.path.basename(idl_file)[:-4] package_path = os.path.join(*tuple(env['PKGPREFIX'].split('.'))) trgs = [ os.path.join(env['IDL_INSTALL_DIRECTORY'], package_path, file) for file in trgs ] except KeyError: trgs = [ os.path.join(env['IDL_INSTALL_DIRECTORY'], file) for file in trgs ] tlist += trgs print 'target:', tlist, '\nsource:', [str(file) for file in source] # return tlist, slist return tlist, source