Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 """General utility functions used by the doil backend"""
00015
00016 from omniidl import idlutil, idltype
00017 from omniidl_be.doil import config
00018 import sys, re, string
00019
00020 try:
00021 import traceback
00022 have_traceback = 1
00023 except:
00024 have_traceback = 0
00025
00026
00027
00028
00029 def fatalError(explanation):
00030 if config.state['Debug']:
00031
00032 print "omniidl: fatalError occurred, in debug mode."
00033 for line in string.split(explanation, "\n"):
00034 print ">> " + line
00035 print "Configuration state:"
00036 print "-------------------------"
00037 config.state.dump()
00038
00039 if have_traceback:
00040 print "Stack:"
00041 print "-------------------------"
00042 traceback.print_stack()
00043 print "Exception:"
00044 print "-------------------------"
00045 traceback.print_exc()
00046 sys.exit(1)
00047
00048 lines = string.split(explanation, "\n")
00049 lines = [ "Fatal error in doil backend", "" ] + lines
00050
00051 for line in lines:
00052 sys.stderr.write("omniidl: " + line + "\n")
00053
00054 sys.stderr.write("""\
00055
00056 For more information (mailing list archives, bug reports etc.) please visit
00057 the webpage:
00058
00059 http://www.openrtm.org/
00060
00061 """)
00062 sys.exit(1)
00063
00064
00065
00066
00067 def unsupportedIDL():
00068 e = """\
00069 Unsupported IDL construct encountered in input.
00070
00071 omniORB does not currently support:
00072 IDL type valuetype
00073 """
00074 fatalError(e)
00075
00076
00077
00078
00079 def union(a, b):
00080 result = a[:]
00081 for x in b:
00082 if x not in result:
00083 result.append(x)
00084 return result
00085
00086 def minus(a, b):
00087 result = []
00088 for x in a:
00089 if x not in b:
00090 result.append(x)
00091 return result
00092
00093 def intersect(a, b):
00094 result = []
00095 for x in a:
00096 if x in b:
00097 result.append(x)
00098 return result
00099
00100 def setify(set):
00101 new_set = []
00102 for x in set:
00103 if x not in new_set:
00104 new_set.append(x)
00105
00106 return new_set
00107
00108
00109
00110 def zip(a, b):
00111 if a == [] or b == []: return []
00112 return [(a[0], b[0])] + zip(a[1:], b[1:])
00113
00114 def fold(list, base, fn):
00115 if len(list) == 1:
00116 return fn(list[0], base)
00117 first = fn(list[0], list[1])
00118 rest = [first] + list[2:]
00119 return fold(rest, base, fn)
00120
00121
00122
00123 class Stack:
00124 def __init__(self):
00125 self.__list = []
00126 def push(self, thing):
00127 self.__list.append(thing)
00128 def pop(self):
00129 if self.__list == []: raise "Stack Empty"
00130 thing = self.__list[-1]
00131 self.__list = self.__list[0:-1]
00132 return thing