util.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- python -*-
3 #
4 # @file util.py
5 # @brief doil backend utility module
6 # @date $Date$
7 # @author Noriaki Ando <n-ando@aist.go.jp>
8 #
9 # This module is almost same as omniidl_be/cxx/util.py
10 #
11 # $Id$
12 #
13 
14 """General utility functions used by the doil backend"""
15 
16 from omniidl import idlutil, idltype
17 from omniidl_be.doil import config
18 import sys, re, string
19 
20 try:
21  import traceback
22  have_traceback = 1
23 except:
24  have_traceback = 0
25 
26 
27 ## Fatal error handling function ##################################
28 
29 def fatalError(explanation):
30  if config.state['Debug']:
31  # don't exit the program in debug mode...
32  print "omniidl: fatalError occurred, in debug mode."
33  for line in string.split(explanation, "\n"):
34  print ">> " + line
35  print "Configuration state:"
36  print "-------------------------"
37  config.state.dump()
38 
39  if have_traceback:
40  print "Stack:"
41  print "-------------------------"
42  traceback.print_stack()
43  print "Exception:"
44  print "-------------------------"
45  traceback.print_exc()
46  sys.exit(1)
47 
48  lines = string.split(explanation, "\n")
49  lines = [ "Fatal error in doil backend", "" ] + lines
50 
51  for line in lines:
52  sys.stderr.write("omniidl: " + line + "\n")
53 
54  sys.stderr.write("""\
55 
56 For more information (mailing list archives, bug reports etc.) please visit
57 the webpage:
58 
59  http://www.openrtm.org/
60 
61 """)
62  sys.exit(1)
63 
64 # Called whenever an unsupported IDL construct is found in the input
65 # (necessary because the front end supports all the new CORBA 2.3
66 # constructs whereas the ORB and correspondingly this backend does not)
68  e = """\
69 Unsupported IDL construct encountered in input.
70 
71 omniORB does not currently support:
72  IDL type valuetype
73 """
74  fatalError(e)
75 
76 
77 ## Set manipulation functions ######################################
78 
79 def union(a, b):
80  result = a[:]
81  for x in b:
82  if x not in result:
83  result.append(x)
84  return result
85 
86 def minus(a, b):
87  result = []
88  for x in a:
89  if x not in b:
90  result.append(x)
91  return result
92 
93 def intersect(a, b):
94  result = []
95  for x in a:
96  if x in b:
97  result.append(x)
98  return result
99 
100 def setify(set):
101  new_set = []
102  for x in set:
103  if x not in new_set:
104  new_set.append(x)
105 
106  return new_set
107 
108 ## List manipulation functions #####################################
109 
110 def zip(a, b):
111  if a == [] or b == []: return []
112  return [(a[0], b[0])] + zip(a[1:], b[1:])
113 
114 def fold(list, base, fn):
115  if len(list) == 1:
116  return fn(list[0], base)
117  first = fn(list[0], list[1])
118  rest = [first] + list[2:]
119  return fold(rest, base, fn)
120 
121 ## Assorted other functions ########################################
122 
123 class Stack:
124  def __init__(self):
125  self.__list = []
126  def push(self, thing):
127  self.__list.append(thing)
128  def pop(self):
129  if self.__list == []: raise "Stack Empty"
130  thing = self.__list[-1]
131  self.__list = self.__list[0:-1]
132  return thing
def setify(set)
Definition: util.py:100
def zip(a, b)
List manipulation functions #####################################.
Definition: util.py:110
def union(a, b)
Set manipulation functions ######################################.
Definition: util.py:79
def unsupportedIDL()
Definition: util.py:67
def fatalError(explanation)
Fatal error handling function ##################################.
Definition: util.py:29
def pop(self)
Definition: util.py:128
def __init__(self)
Definition: util.py:124
def minus(a, b)
Definition: util.py:86
def push(self, thing)
Definition: util.py:126
Assorted other functions ########################################.
Definition: util.py:123
def intersect(a, b)
Definition: util.py:93
def fold(list, base, fn)
Definition: util.py:114


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:56